Usart Asm 12f1822
Usart Asm 12f1822
Usart Asm 12f1822
; CONFIG1
; __config 0xC9E4
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF
& _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
; CONFIG2
; __config 0xDCFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF
;variables
CBLOCK 0X20
CCP1L
CCP1H
VAR_TEMP
R1
AD_H ; AD RESULT HI
AD_L ; AD RESULT LOW
ENDC
org 0x00
; SELECIONADO LA FOSC A 8 MHZ
BANKSEL OSCCON
MOVLW 0X70
MOVWF OSCCON
; CLEAR PORTA & LATCHA
BANKSEL PORTA
CLRF PORTA
BANKSEL LATA
CLRF LATA
BANKSEL TRISA
MOVLW B'00111010'
MOVWF TRISA
; INIT A/D TO WORK WITH INTERNAL CLOCK
BANKSEL ADCON1
MOVLW B'10000000' ; AD RIGHT JUSTIFIED, VREF = VDD COV_CLK 1uS.
MOVWF ADCON1
MOVLW B'00001101' ; AD ON AND SELECT CHANEEL AN3
MOVWF ADCON0
;PROGRAMA
READ_AD
BANKSEL ADCON0
BSF ADCON0,GO ;START A/D
NOP
NOP
AD_WAIT
BTFSC ADCON0,GO ;WAIT FOR END OF CONVERTION
GOTO AD_WAIT
MOVF ADRESH,W ;READ AD_H
BANKSEL PORTA
MOVWF AD_H
BANKSEL ADCON0
MOVF ADRESL,W ;READ AD_L
BANKSEL PORTA
MOVWF AD_L
;envio de datos
BANKSEL PORTA
CLRF R1
MOVLW 0x6F
MOVWF CCP1L
MOVLW 0X80
MOVWF CCP1H
;DESPLAZAMIENTO
RLF CCP1H,F
RLF CCP1L,F
RLF R1,F
RLF CCP1H,F
RLF CCP1L,F
RLF R1,F
;CONVERSION
ADDWF PCL,F
SEND_CRLF1
movlw 0x20 ; CR
CALL TX_BYTE_GP7
MOVLW 0X20 ; LF
CALL TX_BYTE_GP7
RETURN
SEND_CRLF
movlw 0x0D ; CR
CALL TX_BYTE_GP7
MOVLW 0X0A ; LF
CALL TX_BYTE_GP7
RETURN
FIN
END