*********************************************** * * * load_tr.s * * * * -Author : Mariusz Zaczek (zaczek@uiuc.edu) * * -Date : 02/27/2000 * * * *********************************************** opt nolist *********************************************** * * * This code is used for the TRANSMITTER side * * of the robot control system. The primary * * purpose of this code is to read the inputs * * from the joystick. These include 8 on/off * * inputs from the buttons and read by Port E. * * Also, 3 potentiometer inputs read from an * * A/D converter and by Port F...Port QS is * * used to select which pot to read by the A/D * * converter. * * * * Transmission begins when first button is * * pressed. * * * * Register usage: * * D0 - all purpose * * D1 - 8 on/off inputs * * D2 - Pot 1 * * D3 - Pot 2 * * D4 - Pot 3 * * D5 - * * D6 - Checksum * * D7 - Mode: Nice/Bad * * * *********************************************** * * EQUATES * LETTER_A equ %01000001 * HEX $41 LETTER_B equ %01000010 * HEX $42 LETTER_C equ %01000011 * HEX $43 max_X equ $e8 * 222/256 +5 VDC min_X equ $24 * 46 " " max_Y equ $e1 * 215 " " min_Y equ $1d * 39 " " Grip_Open equ $f0 * 230 " " Grip_Closed equ $0b * 21 " " include equ332.asm org $9000 * * Start * * - This is where it all begins ... * Start jsr InitSys * Initialize System move.w #$2700,SR jsr PortEInit * Initialize Port E (Input) jsr PortFInit * Initialize Port F (Input) jsr SCIInit * Initialize SCI for transmitter jsr EnableTrans * Enable SCI to transmit after button press * Initialize Port QS as Output ... 7pins only * NOTE: This initialization must come after the TE bit in SCCR1 is * set otherwise there is a conflict with the TxD. Thus it comes * after the SCI initialization routine and after the SCI is * finally enabled to TRANSMIT. jsr PortQSInit * * Main_Loop * * - Main program body. * Main_Loop jsr CaptureData * Get data from pots and i/o jsr CalculateData * Determine PWM values... jsr CalculateChecksum * Calculate Checksum jsr SendGarbage * Send 1 byte of garbage jsr SendHeader * Send header byte twice jsr SendData * Send data ... 4 bytes + Checksum bra Main_Loop * Loop * * InitSys * * - Initializes system... * InitSys clr.b (SYPCR).L move.b #$7F,(SYNCR).L rts * End ( InitSys ) * * CaptureData * * - Reads Port E and Port F for data... * ...stores in registers, D1,D2,D3 & D4 * CaptureData clr.l D1 * Clear regs. so as to set the TDRE clr.l D2 * bits to 0 (clear TDRE) clr.l D3 clr.l D4 move.b PORTE0,D1 * Capture 8 on/off inputs * Start sequence for reading potentiometers * bits 2,1,0 will be for pot select (000, 001) * bit 3 will be for ALE * bit 4 will be for START * bit 5 will be for Output Enable jsr Delay1u jsr Delay1u jsr Delay1u jsr Delay1u * * Pot #1 (000) * move.b #%00000000,PORTQS * Clear Port QS, set to Pot #1 jsr Delay1u move.b #%00001000,PORTQS * Set ALE bit jsr Delay1u jsr Delay1u move.b #%01011000,PORTQS * Set START bit jsr Delay1u jsr Delay1u move.b #%01010000,PORTQS * Clear ALE bit jsr Delay1u jsr Delay1u move.b #%00000000,PORTQS * Clear START bit jsr Delay125u * Delay 125microseconds move.b #%00100000,PORTQS * Enable Output jsr Delay1u jsr Delay1u move.b PORTF0,D2 * Send Ouput to D2 reg. jsr Delay1u jsr Delay1u jsr Delay1u jsr Delay1u * * Pot #2 (001) * move.b #%00000001,PORTQS * Clear Port QS, set to Pot #2 jsr Delay1u move.b #%00001001,PORTQS * Set ALE bit jsr Delay1u jsr Delay1u move.b #%01011001,PORTQS * Set START bit jsr Delay1u jsr Delay1u move.b #%01010001,PORTQS * Clear ALE bit jsr Delay1u jsr Delay1u move.b #%00000001,PORTQS * Clear START bit jsr Delay125u move.b #%00100001,PORTQS * Enable Output jsr Delay1u jsr Delay1u move.b PORTF0,D3 * Send Ouput to D3 reg. jsr Delay1u jsr Delay1u jsr Delay1u jsr Delay1u * * Pot #3 (010) * move.b #%00000010,PORTQS * Clear Port QS, set to Pot #2 jsr Delay1u move.b #%00001010,PORTQS * Set ALE bit jsr Delay1u jsr Delay1u move.b #%01011010,PORTQS * Set START bit jsr Delay1u jsr Delay1u move.b #%01010010,PORTQS * Clear ALE bit jsr Delay1u jsr Delay1u move.b #%00000010,PORTQS * Clear START bit jsr Delay125u move.b #%00100010,PORTQS * Enable Output jsr Delay1u jsr Delay1u move.b PORTF0,D4 * Send Ouput to D4 reg. rts * End ( CaptureData ) * * CalculateChecksum * * * CalculateChecksum clr.l D6 eor.b D7,D6 eor.b D1,D6 eor.b D2,D6 eor.b D3,D6 eor.b D4,D6 rts * End ( CalculateChecksum ) * * SendGarbage * * * SendGarbage move.w (SCSR).L,D0 andi.w #$0100,D0 beq SendGarbage move.w #%01010101,(SCDR).L rts * End ( SendGarbage ) * * SendHeader * * - Sends the header byte of data (letter A), followed by the * mode byte: B=BAD C=NICE * SendHeader SendHeaderOne move.w (SCSR).L,D0 andi.w #$0100,D0 beq SendHeaderOne move.w #LETTER_A,(SCDR).L SendHeaderTwo move.w (SCSR).L,D0 andi.w #$0100,D0 beq SendHeaderTwo move.w #LETTER_A,(SCDR). SendMode move.w (SCSR).L,D0 * Check if able to send next byte andi.w #$0100,D0 beq SendMode move.w D7,(SCDR).L * if so then send "mode" letter rts * End ( SendHeader ) * * SendData * * - Sends 4 different bytes of data. * SendData * * 8 on/off buttons * SendFirst move.w (SCSR).L,D0 andi.w #$0100,D0 beq SendFirst move.w D1,(SCDR).L * * Left/Right Joystick Pot * SendSecond move.w (SCSR).L,D0 andi.w #$0100,D0 beq SendSecond move.w D2,(SCDR).L * * Up/Down Joystick Pot * SendThird move.w (SCSR).L,D0 andi.w #$0100,D0 beq SendThird move.w D3,(SCDR).L * * 3rd Pot of Joystick * SendFourth move.w (SCSR).L,D0 andi.w #$0100,D0 beq SendFourth move.w D4,(SCDR).L * * Send Checksum * SendChecksum move.w (SCSR).L,D0 andi.w #$0100,D0 beq SendChecksum move.w D6,(SCDR).L SendEnd rts * End ( SendData ) * * PortEInit * * - Intializes all pins of Port E to input pins. * PortEInit move.b #$00,PORTE0 * Clear the data register move.b #$00,PEPAR * Configure Port E as I/O move.b #$00,DDRE * Configure Port E as input rts * End ( PortEInit ) * * PortFInit * * - Intializes all pins of Port F to input pins. * PortFInit move.b #$00,PORTF0 * Clear the data register move.b #$00,PFPAR * Configure Port F as I/O move.b #$00,DDRF * Configure Port F as input rts * End ( PortFInit ) * * PortQSInit * * - Initialize Port QS to output (only 7 pins available) * PortQSInit move.b #$00,PORTQS * Clear data register move.b #$80,PQSPAR * 0-6 I/O, bit 7 TxD move.b #$ff,DDRQS * Set all pins as Digital Output rts * End ( PortQSInit ) * * SCIInit * * - Setup the SCI to have baud rate of 9600 * SCIInit move.w #$0037,(SCCR0).L * Set the SCI baud rate to 9600 move.w #$0000,(SCCR1).L * Clear SCCR1 ... enable later rts * End ( SCIInit ) * * EnableTrans * * - Enable the transmitter of SCI...reads PORT E to determine if button * number 1 is pressed...is YES then SCI transmitter is enabled. * EnableTrans move.b PORTE0,D0 * If button is pressed then andi.w #$0001,D0 beq EnableTrans move.b PORTE0,D0 andi.w #$80,D0 beq NiceMode BadMode move.w #LETTER_B,D7 jmp Transmit NiceMode move.w #LETTER_C,D7 Transmit move.w #$0008,(SCCR1).L * enable the transmitter rts * End ( EnableTrans ) * * CalculateData * * - Determine Pot position and scale to 0-256 * CalculateData Pot1 clr.l D5 * Clear reg 5 move.w #max_X,D5 * Set D5 to max X value sub.w #min_X,D5 * Calculate range between max & min sub.w #min_X,D2 * Subtract min value to get numerator mulu.w #$ff,D2 divu.w D5,D2 * Scale value to 0-256 Pot2 clr.l D5 * Clear reg 5 move.w #max_Y,D5 * Set D5 to max Y value sub.w #min_Y,D5 * Calculate range between max & min sub.w #min_Y,D3 * Subtract min value to get numerator mulu.w #$ff,D3 divu.w D5,D3 * Scale value to 0-256 Pot3 clr.l D5 * Clear reg 5 move.w #Grip_Open,D5 * Set D5 to max X value sub.w #Grip_Closed,D5 * Calculate range between max & min sub.w #Grip_Closed,D4 * Subtract min value to get numerator mulu.w #$ff,D4 divu.w D5,D4 * Scale value to 0-256 CalculateDataEnd rts * End ( CalculateData ) * * Delay 125 microseconds * Delay125u clr.l D5 Delay125uMid cmp.l #5000,D5 bge Delay125uEnd nop add.l #1,D5 jmp Delay125uMid Delay125uEnd rts * * Delay 1 microseconds * Delay1u clr.l D5 Delay1uMid cmp.l #400,D5 bge Delay1uEnd nop add.l #1,D5 jmp Delay1uMid Delay1uEnd rts