RECEPTOR CODIGO EN ASSEMBLER ;************************************************************************ list p=16f84a ;selecion de pic radix hex ; codigo hex pc equ 02h status equ 03h portb equ 06h PORTA equ 05h PIR1 equ 0ch RCSTA equ 18h RCREG equ 1ah trisb equ 86h TRISA equ 85h TXSTA equ 98h SPBRG equ 99h t1 equ 20h t2 equ 21h t3 equ 22h t4 equ 23h var1 equ 24h tem equ 25h tem1 equ 26h loops equ 27h loops2 equ 28h datos equ 29h dato1 equ 2Ah r0e equ 2Bh conta equ 2ch conta1 equ 2Dh e equ 1h rs equ 0h org goto org 0x00 inicio 0X05 inicio clrf status bsf status,5 ; bcf status,6 ;seleciona banco 1 movlw0x0c ;w=0000 1100 movwftrisb ;portb=0000 1100 para el lcd bsf TRISA,0 ;de salida portc.0 bcf TRISA,1 bcf status,5 clrf t1 clrf t2 clrf t3
clrf call call call t4 LCD retardo LCD1 xxyy bcf PORTA,1 ;envia señal que esta listo para recibir datos / despues de mostrar datos en LCD ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; rutina de recepcion ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; recibir1 nop clrf dato1 goto recibir1 call unoymedio rcvr1 movlw 8 movwf conta siguient1 bcf status,0 bsf status,0 rrf dato1 call delayl decfsz conta goto rnext1 movf dato1,0 movwft1 recibir2 nop clrf dato1 goto recibir2 call unoymedio rcvr2 movlw 8 movwf conta siguient2 bcf status,0 bsf status,0 rrf dato1 call delayl decfsz conta goto rnext2 movf dato1,0
movwft2 recibir3 nop clrf dato1 goto recibir3 call unoymedio rcvr3 movlw 8 movwf conta siguient3 bcf status,0 bsf status,0 rrf dato1 call delayl decfsz conta goto rnext3 movf dato1,0 movwft3 recibir4 nop clrf dato1 goto recibir4 call unoymedio rcvr4 movlw 8 movwf conta siguient4 bcf status,0 bsf status,0 rrf dato1 call delayl decfsz conta goto rnext4 movf dato1,0 movwft4 bsf call goto PORTA,1 LCD1 xxyy unoymedio movlw.249 goto startup
delayl movlw.166 startup movwf r0e redo nop nop decfsz r0e goto redo ;;;;;;;;;;;;;;;;;;;;;;;rutinas de muestreo en el LCD ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; control bcf portb,rs ;rs=0,bit.0=1 selecciona registro control...portb= 0000 0000 goto dato2 dato bsf portb,rs ;rs=1, selecciona registro de datos portb= 0000 0001 dato2 bsf portb,e ;e=1, bit.1=1 habilita lcd... portb= 0000 0011 movwfdatos ;copia el valor del registro dato/control en la variable dato...dato=0010 0011 movlw0xf0 ;w=1111 0000 andwf datos,0 ;w=0010 0000 iorwf portb,1 ;portb=0010 0011 bcf portb,e ;portb=0010 0001 bsf portb,e ;portb=0010 0011 movlw0x0f ;w =0000 1111 andwf portb,1 ;portb=0000 0011 swapf datos,0 ;w =0011 0010 andlw 0xF0 ;w =0011 0000 iorwf portb,1 ;portb=0011 0011 bcf portb,e clrf portb tabla addwf pc,1
retlw "T" ;1 retlw "1" ;2 retlw ":" ;3 retlw "T" ;4 retlw "2" ;5 retlw ":" ;6 retlw "T" ;7 retlw "3" ;8 retlw ":" ;9 retlw "T" ;10 retlw "4" ;11 retlw ":" ;12 LCD ;;;;;;;;;;;;; muestra los valores de t1 /t2/t3/t4=0 begin movlw01h ; movlw02h ; (2) definicion de bus de 4 bits, w=0000 0010 limpia pantalla movlw28h ; (3) w=0010 1000 ratifica datos de 4 bits y 2lineas movlw0ch ; (4) w=0000 1100 activa pantalla movlw06h ; (5) w=0000 0110 mensaje fijo n pantalla y muestra ;(5) ciclo de lectura de la tabala q contiene el mensaje clrf var1 ;variable n para que aparezca la cantidad de datos movlw0x80 ;ubica el cursor en la posicion xxx1 movf var1,0 ; n=w call tabla incf var1,1 movlw0x03 ;copio el valor de n en W xorwf var1,0 ;operacion logica entre el w y la variable pulso btfss status,2 ;op=0 =>z=1 y op=1 =>z=0 goto xxx1 movlw0x89 xxx2 movf var1,0 ; n=w call tabla incf var1,1 movlw0x06 ;ubica el cursor en la posicion ;copio el valor de n en W
xorwf var1,0 ;operacion logica entre el w y la variable pulso btfss status,2 ;op=0 =>z=1 y op=1 =>z=0 goto xxx2 movlw0xc0 ;ubica el cursor en la posicion xxx3 movf var1,0 ; n=w call tabla incf var1,1 movlw0x09 ;copio el valor de n en W xorwf var1,0 ;operacion logica entre el w y la variable pulso btfss status,2 ;op=0 =>z=1 y op=1 =>z=0 goto xxx3 movlw0xc9 ;ubica el cursor en la posicion xxx4 movf var1,0 ; n=w call tabla incf var1,1 movlw0x0c ;copio el valor de n en W xorwf var1,0 ;operacion logica entre el w y la variable pulso btfss status,2 ;op=0 =>z=1 y op=1 =>z=0 goto xxx4 ;;;;;;;;;;;;;;;;;;;;;;;; muestra valores LCD1 movlw0x83 ;ubica el cursor en la posicion movf t1,0 ;copio t1 en w movwftem ;guardo w en tem call decena movf tem1,0 movf tem,0 movlw b'11011111' movlw b'01000011' movlw0x8c ;ubica el cursor en la posicion movf t2,0 ;copio t1 en w movwftem ;guardo w en tem call decena
movf tem1,0 movf tem,0 movlw b'11011111' movlw b'01000011' movlw0xc3 ;ubica el cursor en la posicion movf t3,0 ;copio t1 en w movwftem ;guardo w en tem call decena movf tem1,0 movf tem,0 movlw b'11011111' movlw b'01000011' movlw0xcc ;ubica el cursor en la posicion movf t4,0 ;copio t1 en w movwftem ;guardo w en tem call decena movf tem1,0 movf tem,0 movlw b'11011111' movlw b'01000011' ;;; aqui viene el valor de t1 ò t2 ò t3 ò t4 en la variable 'tem'
decenamovlw 0x5a ;90 goto unidad1 movlw 0x50 ;80 goto unidad2 movlw 0x46 ;70 goto unidad3 movlw 0x3c ;60 goto unidad4 movlw 0x32 ;50 goto unidad5 movlw 0x28 ;40 goto unidad6 movlw 0x1e ;30 goto unidad7 movlw 0x14 ;20 goto unidad8 movlw 0x0a ;10 goto unidad9 goto unidada unidad1 movlw 0x5a ;w=90 movlw 0x09 ;w=04
;copiamos 4 en tem(decena) ;sumamos w+tem1=tem1 unidad2 movlw 0x50 ;w=80 movlw 0x08 ;w=08 ;copiamos 8 en tem(decena) ;sumamos w+tem1=tem1 unidad3 movlw 0x46 ;w=70 movlw 0x07 ;w=07 ;copiamos 4 en tem(decena) ;sumamos w+tem1=tem unidad4 movlw 0x3c ;w=60 movlw 0x06 ;w=04 ;copiamos 6 en tem(decena) unidad5 movlw 0x32 ;w=50 movlw 0x05 ;w=05 ;copiamos 5 en tem(decena) unidad6 movlw 0x28 ;w=40
movlw 0x04 ;w=04 ;copiamos 4 en tem(decena) unidad7 movlw 0x1e ;w=30 movlw 0x03 ;w=03 ;copiamos 3 en tem(decena) unidad8 movlw 0x14 ;w=20 movlw 0x02 ;w=02 ;copiamos 2 en tem(decena) unidad9 movlw 0x0a ;w=10 movlw 0x01 ;w=01 ;copiamos 1 en tem(decena) unidada movlw 0x30 movlw 0x30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; retardo MOVLW D'50' ;el registro contiene el nº MOVWF loops ; de ms de retardo top2 MOVLW D'100' MOVWF loops2 top NOP NOP
end NOP NOP NOP NOP DECFSZ GOTO DECFSZ GOTO loops2 ; pregunta si termino 1ms top loops ; pregunta si termina el retardo top2