R
randy.day
Guest
I'm working with a PIC2455, trying to get it to send a byte on the EUSART
every few milliseconds.
What is happening is I get a constant pulse train out, rather than
9bits-pause-9bits. I know the timer is working by scoping the A1 pin. I
thought it was because I was sending 0x55 at first, but I still get a pulse
train even when loading 0x00 into TXREG.
It's reassurring that I'm getting something other than a flatline, but
still...
What am I overlooking?
#include <p18F2455.inc>
config LVP = OFF
config XINST = OFF
config CPUDIV = OSC1_PLL2
config PLLDIV = 12 ;12
config WDT = OFF
config MCLRE = OFF
config DEBUG = OFF
config PBADEN = ON
config LPT1OSC = OFF
config FOSC = INTOSCIO_EC
cblock 0x20
TimerVal
RESULTHI
RESULTLO
endc
org 0
goto Start
Start
movlw 0x09 ;'00001001'
movwf TRISA
; BSF TRISA,0 ;Set RA0 to ADC input
; BCF TRISA,1 ;Set RA1 to output
; bsf TRISA,3 ;set A3 for input - pushbutton
movlw 0xFF ; make PORTB all input
movwf TRISB
;setup PORTC for EUSART out
CLRF TRISC
BSF TRISC, 6
;setup ADC
clrf ADCON0
movlw 0x0E
movwf ADCON1
movlw 0xAF
movwf ADCON2
;set timer1 for 2ms operation
clrf T1CON
clrf TMR1H
;set EUSART for Transmit
movlw b'11110111' ;SENDB=0
movwf TXSTA
clrf SPBRGH
movlw 0x01 ;set baud control register for 117.6k
movwf SPBRG ; pg. 244, 4MHz
clrf BAUDCON
bsf BAUDCON, BRG16 ;baud rate bit=high
movlw 0x90
movwf RCSTA
; more timer stuff
movlw 0x00 ;set timer interval
movwf TimerVal
; activate timer
movwf TMR1L
movlw b'10000001'
movwf T1CON
TransmitLoop
BTFSS PIR1, TMR1IF ; wait for timer to go off
goto $-2
setf TMR1H
decf TMR1H
movf TimerVal, w
movwf TMR1L ;reset timer for next countdown
bcf PIR1, TMR1IF
; pulse to trigger scope
BSF PORTA, 1 ;
BCF PORTA, 1
movlw 0x00;55
btfsc RESULTHI, 3
movlw 0x00
BSF TXSTA, TX9D ;set/clear 9th bit before updating TXREG!
movwf TXREG
goto TransmitLoop
end
every few milliseconds.
What is happening is I get a constant pulse train out, rather than
9bits-pause-9bits. I know the timer is working by scoping the A1 pin. I
thought it was because I was sending 0x55 at first, but I still get a pulse
train even when loading 0x00 into TXREG.
It's reassurring that I'm getting something other than a flatline, but
still...
What am I overlooking?
#include <p18F2455.inc>
config LVP = OFF
config XINST = OFF
config CPUDIV = OSC1_PLL2
config PLLDIV = 12 ;12
config WDT = OFF
config MCLRE = OFF
config DEBUG = OFF
config PBADEN = ON
config LPT1OSC = OFF
config FOSC = INTOSCIO_EC
cblock 0x20
TimerVal
RESULTHI
RESULTLO
endc
org 0
goto Start
Start
movlw 0x09 ;'00001001'
movwf TRISA
; BSF TRISA,0 ;Set RA0 to ADC input
; BCF TRISA,1 ;Set RA1 to output
; bsf TRISA,3 ;set A3 for input - pushbutton
movlw 0xFF ; make PORTB all input
movwf TRISB
;setup PORTC for EUSART out
CLRF TRISC
BSF TRISC, 6
;setup ADC
clrf ADCON0
movlw 0x0E
movwf ADCON1
movlw 0xAF
movwf ADCON2
;set timer1 for 2ms operation
clrf T1CON
clrf TMR1H
;set EUSART for Transmit
movlw b'11110111' ;SENDB=0
movwf TXSTA
clrf SPBRGH
movlw 0x01 ;set baud control register for 117.6k
movwf SPBRG ; pg. 244, 4MHz
clrf BAUDCON
bsf BAUDCON, BRG16 ;baud rate bit=high
movlw 0x90
movwf RCSTA
; more timer stuff
movlw 0x00 ;set timer interval
movwf TimerVal
; activate timer
movwf TMR1L
movlw b'10000001'
movwf T1CON
TransmitLoop
BTFSS PIR1, TMR1IF ; wait for timer to go off
goto $-2
setf TMR1H
decf TMR1H
movf TimerVal, w
movwf TMR1L ;reset timer for next countdown
bcf PIR1, TMR1IF
; pulse to trigger scope
BSF PORTA, 1 ;
BCF PORTA, 1
movlw 0x00;55
btfsc RESULTHI, 3
movlw 0x00
BSF TXSTA, TX9D ;set/clear 9th bit before updating TXREG!
movwf TXREG
goto TransmitLoop
end