; FILE: rcv4800.asm ; AUTH: P.Oh ; DATE: 04/25/02 23:50 ; DESC: PC-to-PIC serial communications ; VERS: 04/25/02 - 1.0 See PIC'n Techniques p. 219 ;-------------------------------------------------------------------------- list p=16f84 radix hex ;-------------------------------------------------------------------------- ; CPU EQUATES tmr0 equ 0x01 ; timer/counter register status equ 0x03 ; status word register portA equ 0x05 ; port A register portB equ 0x06 ; port B register intCon equ 0x0b ; interrupt control register rcvReg equ 0x0c ; general purpose register count equ 0x0d ; general purpose register temp equ 0x0e ; general purpose register optReg equ 0x81 ; file register in Bank 1 trisA equ 0x85 ; file register in Bank 1 trisB equ 0x86 ; file register in Bank 1 ;-------------------------------------------------------------------------- ; BIT EQUATES rp0 equ 5 ;-------------------------------------------------------------------------- org 0x000 start bsf status, rp0 ; Switch to Bank 1 movlw b'00000101' ; A0, A2 are input and the rest are output movwf trisA movlw b'00000000' ; Port B: all output movwf trisB bcf status, rp0 ; Switch back to Bank 0 clrf portB clrf rcvReg switch btfsc portA, 2 ; Is A2 equal 0? i.e. is switch closed? goto switch ; No, so keep checking call rcv4800 ; Yes, to serial in subroutine movf rcvReg, w ; Get byte received movwf portB ; Display byte on the 8 LEDs circle goto circle ; Done ;-------------------------------------------------------------------------- rcv4800 bcf intCon, 5 ; Disable tmr0 interrupts bcf intCon, 7 ; Disable global interrupts clrf tmr0 ; Clear timer/counter clrwdt ; Clear wdt prep prescaler assign bsf status, rp0 ; to page 1 movlw b'11011000' ; set up timer/counter movwf optReg bcf status, rp0 ; Back to page 1 movlw 0x08 ; Init shift counter movwf count sbit btfsc portA, 0 ; Look for start bit goto sbit ; For Mark movlw 0x98 ; movwf tmr0 ; Load and start timer/counter bcf intCon, 2 ; Clear tmr0 overflow flag time1 btfss intCon, 2 ; Has the timer (bit 2) overflowed? Skip next line if 1 goto time1 ; No btfsc portA, 0 ; Start bit still low? goto sbit ; False start, go back movlw 0x30 ; real, define N for timer movwf tmr0 ; start timer/counter - bit time bcf intCon, 2 ; Clear tmr0 overflow flag time2 btfss intCon, 2 ; Timer overflow? goto time2 ; No movlw 0x30 ; Yes, define N for timer movwf tmr0 ; Start timer/counter bcf intCon, 2; ; Clear tmr0 overflow flah movf portA, w ; Read port A movwf temp ; Store rrf temp, f ; Rotate bit 0 into carry flag rrf rcvReg, f ; Rotate carry into rcvReg bit 7 decfsz count, f ; Shifted 8? goto time2 ; No time3 btfss intCon, 2 ; Timer overflow? goto time3 ; No return ; Yes, byte received ;----------------------------------------------------------------------- end ;----------------------------------------------------------------------- ; At blast time, select: ; memory unprotected ; watchdog timer disabled ; standard crystal (4 MHz) ; power-up timer on ;=======================================================================