Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Usart Asm 12f1822

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

list p= 12f1822

; PIC12F1822 Configuration Bit Settings


; Assembly source line config statements
#include "p12f1822.inc"

; 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

;INIT UART A 9600 8BIT 1 STOP

BANKSEL SPBRGH ; SELECT BANK3 FOR THE UART REG.


CLRF SPBRGH ; 9600 BAUD, SYNC =0 BRGH = 0 BRG16=0 RST VALUES
MOVLW .12 ; BR = FOSC7[64(N+1)] n = 12 DECIMAL
MOVWF SPBRGL
BSF RCSTA,SPEN ; ENABLE SERIAL PORT
BSF TXSTA,TXEN ; ENABLE TX PART
BSF RCSTA,CREN ; ENABLE RX PART

;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

MOVF R1,W ;SIPLAY DE MSB IN 2 HEX DIGITS


CALL DISP_HEX
MOVF CCP1L,W ; DISPLAY THE LSB
CALL DISP_HEX
movlw 0x20 ; CR
CALL TX_BYTE_GP7
MOVLW 0X4E ; LF
CALL TX_BYTE_GP7
MOVLW 0X45 ; LF
CALL TX_BYTE_GP7
MOVLW 0X52 ; LF
CALL TX_BYTE_GP7
MOVLW 0X4F ; LF
CALL TX_BYTE_GP7
CALL SEND_CRLF
GOTO FIN

INT2HEX ; CONVERT INT (< 0X0F) IN (W) TO HEX (w)

ADDWF PCL,F

DT "0123456789ABCDEF" ; RET HEX IN W

DISP_HEX ; DISPLAY A BYTE (W) IN HEX FORMAT


MOVWF VAR_TEMP
SWAPF VAR_TEMP,W ;GET HI NIBLE
ANDLW 0x0F
CALL INT2HEX ;CONVERT HI NIBLE TO HEX
CALL TX_BYTE_GP7 ; SENT HI_N HEX
MOVF VAR_TEMP,W ; GET LOW NIBLE CONV. AND SEND
ANDLW 0x0F
CALL INT2HEX
CALL TX_BYTE_GP7
RETURN

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

TX_BYTE_GP7 ; TX A BYTE FOR TX O PIN:7


BANKSEL TXSTA
BTFSS TXSTA,TRMT ;TX SHIFT EMPTY
GOTO $-1
MOVWF TXREG
BANKSEL PORTA
RETURN

FIN
END

You might also like