Re: pic16f690
Here is my intial codes guys. Please advice me on what to do next or tell me where I went wrong on the coding.
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
errorlevel -302
;******* Start at the reset vector
Cblock 0x20
temp ; Assign an address to hold receive signal
endc
org 0x000
Start
org 0x010
clrf PORTC
bCf STATUS,RP0 ;bank 1
bsf STATUS,RP1
;****************************************************
movlw b'10101111'
movwf TRISB ;portB [Pin 11 & Pin 13] outputs** <5,7> set for RX/TX
;**********************************************
Receive:
bCf STATUS,RP0 ;bank 1
bSf STATUS,RP1
movlw d'25' ; Set Baud rate, 9600 BPS
movwf SPBRG
bcf BAUDCTL,4 ;transmit non-inverted data to pin RB7
bcf BAUDCTL,3 ;use 8 bit baud generator BRG16
bcf BAUDCTL,1 ;edges do not generate interrupts
bcf BAUDCTL,0 ;disables auto-baud ABDEN
bCf STATUS,RP0 ;bank 0
bcf STATUS,RP1
bcf RCSTA,RX9 ; 8 BIT RECEPTION
bsf RCSTA,CREN ;ENABLES RECEIVER
bsf RCSTA,SPEN ;**** Serial ENABLED
bsf PIR1,TXIF ;**Set interrupt
movf RCREG,temp ; move data of rcreg to temp
bCf STATUS,RP0 ;bank 1
bSf STATUS,RP1
movwf TRISB ;drive the relay at Pin 11 or Pin 13
btfsc TRISB,6 ; test if Pin11 is high
goto Receive ; loop until Pin 11 will be high
Init_ADC
; Set ADCON0
bcf STATUS,RP0 ; Go to Bank 0
bcf STATUS,RP1
movlw b'10000001' ;Right justified, VDD reference bit,pin ANO(pin19), intialize ADC
movwf ADCON0
; Set ADCON1
BANKSEL ADCON1 ; this could be done using this bCf STATUS,RP0 bank 1 bSf STATUS,RP1
movlw b'10000101' ; A/D clock conversion clock FOSC/2
movwf ADCON1
BANKSEL ADCON0
return
Read_ADC
bsf ADCON0, GO_DONE ;initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ;wait for ADC to finish
movf ADRESH,W
andlw 0x03
movwf NumH
BANKSEL ADRESL
movf ADRESL,W
BANKSEL ADRESH
movwf NumL ;return result in NumL and NumH
return
;**********************************************
Main
movlw 0x0f ; not the correct data to be transmitted
movwf TXREG
;********************************************
Wait
btfss PIR1,TXIF
goto Wait ;/**********TXIF will get clear by loading TXREG
goto Buffer
;/*********Ready to load another 8-bit value??*****
Buffer
btfss TXSTA,TRMT
goto Buffer
goto Nextvalue
;/********Next value to be transmit*****
Nextvalue
movlw 0xff
movwf TXREG
Wait1
btfss PIR1,TXIF
goto Wait1 ;/******TXIF will get clear by loading TXREG
goto Buffer1
;/**************
Buffer1
btfss TXSTA,TRMT
goto Buffer1
goto Main
END