FinalTrigger
New Member
Hey guys, in class im working on a serial communication function for the pic16f877a. What i have is of course the microchip, a 10 segment LED (looks like Binary) and a photo resistor. So what im trying to do is a Analog to Digital Conversion (which i was able to complete) but now send the value that was given from the conversion (ADRESH) to an output for communication ( to myself...send and receive) and take the value from the recieve register and move it to PORTD which i have connected to my 10 segment display. I believe i have my interrupts set wrong, because i think the processor is getting stuck and not reseting / continuing. if anyone can help i would highly appreciate it.
Code:
list p=16f877
#include <p16f877a.inc>
org 0x04
goto ISR
org 0x000
goto Start
Start org 0x020
bsf STATUS, 5 ;select Bank 1
bcf STATUS, 6
movlw B'10000111' ;same as 0x87
movwf OPTION_REG ;sets up Timer 0
movlw 0x80
movwf TRISC ;sets pin 1 as input
movlw 0x00
movwf TRISD
bsf PIE1, 4 ;enable TXIE for interupts
bsf PIE1, 5 ;enable RCIE for interupts
bsf PIE1, 6 ;enable ADIE interupt enable bit
bsf TXSTA, 4 ;clear SYNC for asynchronous mode
bsf TXSTA, 5 ;enable the transmission by setting TXEN, also sets TXIF
movlw 0x0c
movwf SPBRG ;sets baud rate for serial port
movlw B'11100000'
movwf INTCON ;sets GIE and PEIE in Interupts
movlw 0x0E
movwf ADCON1 ;set up ADCON1 Register
bcf STATUS, 5 ;select Bank 0
movlw B'00000001' ;set up the ADCON0 Register and clear Go/Done
movwf ADCON0
bcf STATUS, 6
bsf RCSTA, 7 ;set SPEN to enable serial ports
bsf RCSTA, 4 ;enable CREN for reception
clrf PORTD
comf PORTD, f
call LoopTimer
clrf PORTC
;''''''''''''''''''''''''''''Asynch Transmition''''''''''''''''''''''''''''''''''
; movlw 0x0c
; movwf SPBRG ;sets baud rate or serial port
; bcf TXSTA, 4 ;clear SYNC for asynchronous mode
; bsf RCSTA, 7 ;set SPEN to enable serial ports
; bsf PIE1, 4 ;enable TXIE for interupts
; bsf TXSTA, 5 ;enable the transmission by setting TXEN, also sets TXIF
; movlw B'11000000' ;sets GIE and PEIE in Interupts
; movwf INTCON
;''''''''''''''''''''''''''''Asynch Reception''''''''''''''''''''''''''''''''''''
; bsf PIE1, 5 ;enable RCIE for interupts
; bsf RCSTA, 4 ;enable CREN for reception
;'''''''''''''''''''''''''''''''''Main''''''''''''''''''''''''''''''''''''''''''''''
Main ; movfw Recieve
movfw Digital
movwf PORTD
goto Main
;********************************ADC*************************************************
ADC ; movlw B'00000001' ;set up the ADCON0 Register and clear Go/Done
; movwf ADCON0
btfsc ADCON0, 2 ;test the go/done bit in ADCON0 to see if complete
goto $-1 ;go back 1 step to test Go/done
movfw ADRESH ;moves the value in ADRESH to w register
movwf Digital ;moves the value from w register to Digital Register
bsf ADCON0, 2 ;set the Go/Done bit in ADCON0
bcf PIR1, 6 ;clear bit 6 to notify A/D Convertion not complete
return
;''''''''''''''''''''''''''''''''Transmition''''''''''''''''''''''''''''''''''''''''
Transmition movfw Digital
movwf TXREG ;moves digital value to TXREG
bsf PIR1, 4
return
;'''''''''''''''''''''''''''''''''Reception'''''''''''''''''''''''''''''''''''''''''
Reception movfw RCREG
movwf Recieve ;moves Recieving data to Recieve Register to save data
bsf PIR1, 5
return
;*******************************Loop Timer*******************************************
LoopTimer btfss INTCON, 2 ;test for overflow of timer
goto LoopTimer ;loop back until overflow happens
bcf INTCON, 2 ;reset timer overflow bit
return
;'''''''''''''''''''''''''''''''Interupt Service Routine'''''''''''''''''''''''''''''
ISR btfsc PIR1, 6 ;tests ADIF
call ADC
btfsc PIR1, 4 ;tests TXIF
call Transmition
btfsc PIR1, 5 ;tests RCIF
call Reception
btfsc INTCON, 2
call LoopTimer
retfie
;*****************************Registers***********************************************
Digital equ 0x35 ;assign register 0x35 to Digital
Recieve equ 0x36 ;assign register 0x36 to Recieve
end