* * IR_sen.asm - an IR proximity sensor for the Ep2711E9 Rev.C board * (c)2003, EVBplus.com, Written by Wayne Chu * * Function: A robot application by using the IR light beam to detect * an object in its vicinity. * * Instruction: The PD1 will be reset to low to enable the IR transmitter. * The IR light beam will be bounced back by an object, * so the IR receiver will receive the IR light via PD0 and * display the result on the LCD display module. * * Sometime the table surface can reflect the light. * For the best result, place the board near the edge of the * table to reduce the reflection by the table surface. * Two T1 red LEDs near the IR transceiver will indicate * its status. After running the program, make sure that * the TX LED is on and the RX LED is off without an object * in the front of them. If your body is too close to them, * it also will reflect the IR light, so stay 1 foot away * from them. When the RX LED is off, then put your hand * in the front of them and read the LCD display. * * The range is about 6-10 inches and can be increased by * reducing the resister R11's value, but it should not be * smaller than 100 Ohm. * * DB0: equ 1 DB1: equ 2 DB2: equ 4 DB3: equ 8 DB4: equ $10 DB5: equ $20 DB6: equ $40 DB7: equ $80 NOTDB5: equ $DF NOTDB6: equ $BF portd: equ 8 ddrd: equ 9 sccr2: equ $2d REGBLK: equ $1000 STACK: equ $8FFF ONE_MS equ 167 ; for 8 MHz 1000us/6us=167 FIVE_MS equ 835 TEN_MS equ 1670 PORTF equ $2201 DDRF equ $2203 d40us: equ 15 ; 15x6us= 90 us, 60us ok REG_SEL: equ DB0 ; 0=reg, 1=data ENABLE: equ DB1 NOT_REG_SEL: equ $FE NOT_ENABLE: equ $FD org 0 temp1: rmb 1 pfimg: rmb 1 reset_seq: rmb 1 disp_ram: rmb 3 * LCDimg: equ pfimg LCD_RSimg: equ pfimg LCD_ENimg: equ pfimg LCD: equ PORTF LCD_RS: equ PORTF LCD_EN: equ PORTF * org $D000 jmp start lcd_ini: ldaa #$FF staa DDRF clra staa pfimg staa PORTF ldx #inidsp1 ; point to init. codes. ldaa #1 staa reset_seq ; need more delay for first reset seq. jsr outins1 ; output codes. ldx #inidsp2 ; point to init. codes. clr reset_seq jsr outins2 ; output codes. rts inidsp1: fcb 2 ; number of instrutions fcb $33 ; reset char fcb $32 ; reste char inidsp2: fcb 4 ; number of instrutions fcb $28 ; 4bit, 2 line, 5X7 dot fcb $06 ; cursor increment, disable display shift fcb $0c ; display on, cursor off, no blinking fcb $01 ; clear display memory, set cursor to home pos outins1: pshb ; output instruction command. jsr sel_inst ldab 0,x inx onext1: ldaa 0,x jsr wrt_pulse ; initiate write pulse. inx jsr d5ms decb bne onext1 pulb rts * outins2: pshb ; output instruction command. jsr sel_inst ldab 0,x inx onext2: ldaa 0,x jsr wrt_pulse ; initiate write pulse. inx decb bne onext2 jsr d5ms pulb rts * delay_10ms: nop d10ms: pshx ldx #TEN_MS bsr del1 pulx rts d5ms: pshx ldx #FIVE_MS bsr del1 pulx rts del1: dex inx dex bne del1 rts * * sel_data: psha * bset LCD_RSimg REG_SEL ; select instruction ldaa LCD_RSimg oraa #REG_SEL bra sel_i sel_inst: psha * bclr LCD_RSimg REG_SEL ; select instruction ldaa LCD_RSimg anda #NOT_REG_SEL sel_i: staa LCD_RSimg staa LCD_RS pula rts * lcd_line1: jsr sel_inst ; select instruction ldaa #$80 ; starting address for the line1 bra line3 lcd_line2: jsr sel_inst ldaa #$C0 ; starting address for the line2 line3: jsr wrt_pulse * jsr sel_data jsr msg_out rts * at entry, x must point to the begining of the message, * b = number of the character to be sent out * msg_out: ldaa 0,x jsr wrt_pulse inx decb bne msg_out rts * * @ enter, a=data to output * wrt_pulse: pshx psha ; save it tomporarily. anda #$f0 ; mask out 4 low bits. staa temp1 ; save nibble value. ldaa LCDimg ; get LCD port image. anda #$0f ; need low 4 bits. oraa temp1 ; add in low 4 bits. staa LCDimg ; save it staa LCD ; output data * bsr enable_pulse ldaa reset_seq beq wrtpls jsr d5ms ; delay for reset sequence * wrtpls: pula asla ; move low bits over. asla asla asla staa temp1 ; store temporarily. * ldaa LCDimg ; get LCD port image. anda #$0f ; need low 4 bits. oraa temp1 ; add in loiw 4 bits. staa LCDimg ; save it staa LCD ; output data * bsr enable_pulse pulx rts * enable_pulse: * bset LCD_ENimg ENABLE ; ENABLE=high ldaa LCD_ENimg oraa #ENABLE staa LCD_ENimg staa LCD_EN * bclr LCD_ENimg ENABLE ; ENABLE=low ldaa LCD_ENimg anda #NOT_ENABLE staa LCD_ENimg staa LCD_EN pshx ldx #d40us jsr del1 pulx rts start: lds #STACK jsr delay_10ms ; delay 20ms during power up jsr delay_10ms ldx #REGBLK clr sccr2,x ; disable SCI, it was enabled by BUFFALO * ldaa #2 staa ddrd,x ; PD0=input, PD1=output clr portd,x ; make PD1=0 to xmit IR light jsr lcd_ini ; initialize the LCD back: ldaa portd+$1000 rora ; rotate PD0 into carry bit bcs no_IR_light ldx #MSG2 ; MSG2 for line2, x points to MSG2 ldab #16 ; send out 16 characters jsr lcd_line1 jsr delay_10ms jsr delay_10ms jmp back no_IR_light: ldx #MSG1 ; MSG1 for line1, x points to MSG1 ldab #16 ; send out 16 characters jsr lcd_line1 * jsr delay_10ms jsr delay_10ms jmp back MSG1: FCC "NO OBJECT NEARBY" MSG2: FCC "OBJECT DETECTED " end