This is a test of two routines that went into a security system. Commenting's not too bad, some LCD delays not optimised but it works OK. It was written in MPLAB and will compile. I put the routines into a larger program and worked on them there, it would be difficult to extract them now. And of course it looks much prettier in Courier ============================================== ;rx_disp.asm ;get RS232 from PC, display ;Joe Colquitt, 5th November 2001 list p=16F628 #include ;3.686400 MHz crystal. LCD Timing loops originally for 10MHz ; ;Baud rate = 9600 = 3686400/(64 x (5+1)) ; ;Receive 10 bytes from PC and display on LCD screen ; ;LCD is Citizen 20 x 2 alphanumeric ;line 1 address = #00 +high bit = #80 ;line 2 address = #40 +high bit = #c0 ; ;;LCD pinout, 14-pin header - 1 Vss 2 V+ ; 3 Vlc 4 RS ; 5 RW 6 E ; 7 d0 8 d1 ; 9 d2 10 d3 ; 11 d4 12 d5 ; 13 d6 14 d7 ; ;Porta.0 LCD d0 ; 1 d1 ; 2 d2 ; 3 d3 ; ; 4 LCD Register Select ; ;Portb.0 LCD Enable ; 1 USART Rx ; 2 USART Tx ; 3 LCD Read/Write ; ; 4 LCD d4 ; 5 d5 ; 6 d6 ; 7 d7 rs equ 0x04 en equ 0x00 rw equ 0x03 start equ 0x00 ;program start vector ram equ 0x20 ;start of RAM index equ ram+0 cnt1 equ ram+1 cnt2 equ ram+2 cnt3 equ ram+3 cnt4 equ ram+4 endlp equ 0x04 ;data fetch loop limit flag temp1 equ ram+5 temp2 equ ram+6 rxhold equ ram+7 cksum equ ram+8 ;checksum for transmitted data fsrc equ ram+9 ;fsr copy dram equ ram+0x0a ;storage for transmitted data bflag equ 0x07 ;LCD busy flag ;LCD initialisation values 38h ;display on, no cursor blink 0ch ;entry mode - increment, no shift 06h __config _xt_osc & _wdt_off & _pwrte_on & _lvp_off & _boden_off org 0x00 goto entry entry clrf porta ;...o oooo movlw 0x07 movwf cmcon clrf status ;set rp0, rp1 = 0 = Bank0 ; Boot Baud Rate = 9600, No Parity, 1 Stop Bit bsf status,rp0 movlw 0x05 ;9600 baud @ 3.686400MHz movwf spbrg movlw b'00100000' ;brgh = 0 movwf txsta ;Async Transmission, set brgh movlw b'10010000' ;Async Reception clrf status ;back to page 0 movwf rcsta bsf status,rp0 bcf status,rp1 movlw 0x00 movwf trisa movlw 0x02 ;oooo ooio movwf trisb movlw b'00000010' ; RX Lo, TX Hi movwf portb movlw 0x80 ;portb pull-ups off (bit7) movwf option_reg bcf status,rp0 bcf status,rp1 bcf portb,en ;clear control lines bcf portb,rw bcf porta,rs d4d5 movlw 0x30 ;power-up value on data lines call dataout nop bsf portb,en ;and write it to LCD nop nop nop bcf portb,en movlw 0xc0 ;call 64 x 100us movwf cnt1 call altin2 incf index,f movlw 0x02 ;loop for total of 3 writes xorwf index,w btfss status,z goto d4d5 format clrf index ;get LCD initialisation values floop nop nop movlw 0x02 ;get pattern from $02xx table movwf pclath movf index,w call lcdinit ;fetch data into W call dataout nop bsf portb,en ;and write them to LCD nop nop nop bcf portb,en nop call busy ;test Busy Flag incf index,f movlw 0x03 xorwf index,w btfss status,z goto floop getdata movlw 0x48 ;set LCD address call address clrf index clrf cksum movlw 0x29 ;base address for data storage movwf fsr call receive ;get 20 bytes to display from PC display movlw 0x00 ;line 1, column 0 call address clrf index movlw 0x29 ;set retrieval to base address movwf fsr line1a movf indf,w ;get data byte from ram call write incf fsr,f ;bump ram address incf index,f movlw 0x06 ;check limit xorwf index,w btfss status,z goto line1a movlw 0x20 ;space after 6 characters call write line1b movf indf,w call write incf fsr,f incf index,f movlw 0x0d xorwf index,w btfss status,z goto line1b movlw 0x20 ;space after 13 characters call write line1c movf indf,w call write incf fsr,f incf index,f movlw 0x10 xorwf index,w btfss status,z goto line1c movlw 0x40 call address ;line 2, column 0 clrf index ;print "Pin# " pinloop movlw 0x02 ;get data from 0x2xx bank movwf pclath movf index,w call pin call write incf index,f movlw 0x05 xorwf index,w btfss status,z goto pinloop clrf index line2 movf indf,w call write incf fsr,f incf index,f movlw 0x04 xorwf index,w btfss status,z goto line2 wait goto wait receive nop btfss pir1,rcif ;check "Rx full" IRQ bit goto receive movf rcreg,w movwf indf ;store in data ram addwf cksum,f ;add to checksum incf fsr,f ;bump counter incf index,f movlw 0x14 ;count 20 bytes xorwf index,w btfss status,z goto receive movf cksum,w ;send checksum back to PC movwf txreg txwait bsf status,rp0 btfss txsta,trmt goto txwait bcf status,rp0 return address addlw 0x80 ;set high bit of address command call dataout ;put address on data lines nop bsf portb,en ;write it to LCD nop bcf portb,en call busy return write bsf porta,rs ;set RS for data write call dataout bsf portb,en ;write it to LCD nop bcf portb,en nop bcf porta,rs nop call busy nop return point1 movlw 0x64 ;call 1ms routine 100 times altin1 movwf cnt3 ;(or enter here with W) p1delay call msdelay decfsz cnt3,f goto p1delay return msdelay movlw 0xf6 ;enter here for 1ms movwf cnt1 altin2 clrf cnt2 ;here for mults of 100us inc incfsz cnt2,f goto inc incfsz cnt1,f goto inc return busy bsf portb,rw ;set RW for Read nop call msdelay bcf portb,rw return bsf status,rp0 bcf status,rp1 movlw 0x80 ;make b7 an input movwf trisb bcf status,rp0 bcf status,rp1 bsf portb,en rdbusy btfsc portb,bflag ;loop until Busy Flag clear goto rdbusy bcf portb,en nop bcf portb,rw bsf status,rp0 bcf status,rp1 movlw 0x00 ;b7 as output again movwf trisb bcf status,rp0 bcf status,rp1 return dataout movwf temp1 ;copy of data to send andlw 0x0f ;mask out upper nybble, porta data in W movwf temp2 ;copy movf porta,w andlw 0xf0 ;clear porta lower nybble addwf temp2,w movwf porta ;put data into porta lower nybble movf temp1,w ;get original andlw 0xf0 ;mask out lower nybble, portb data in W movwf temp2 ;copy movf portb,w andlw 0x0f ;clear portb upper nybble addwf temp2,w movwf portb ;put data into portb upper nybble return org 200h lcdinit addwf pcl,f retlw 0x38 retlw 0x0c retlw 0x06 pin addwf pcl,f retlw 0x50 ;"PIN# " retlw 0x69 retlw 0x6e retlw 0x23 retlw 0x20 end -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.