xtal (cystal)!
ok, i'm a newbie. i wasn't using an external crystal for the pic timing. apparently the internal oscillator is useless. (thanks tom!)
so here's my new schematic. i'll be using an 18.432MHz xtal. it has three connections: two connect to clk1 and clk2 on the pic, and one connects to VDD.
tom also sent me some quick code that uses the USART component of the pic, so i don't have to do bit-banging anymore.
code snippet (courtesy tom jennings):
(cut and paste it directly, there are tabs in there that html isn't displaying)
; Initialize the UART for asyncrhonous in and out
; and set the bit rate. This sets PB2 (TD) as output,
; PB1 (RXD) as input and sets the bit rate to the factor
; W. See PIC16F628a data sheet PDF page 73-75.
serinit
banksel TRISB ; bank
bsf TRISB, RXD ; 1 RB1 is input, RD
bcf TRISB, TXD ; 1 RB2 is output, TD
bcf TXSTA, BRGH ; 1 set LOW B.R. range,
movwf SPBRG ; 1 set bit rate divisor,
bsf TXSTA, TXEN ; 1 Tx enable
banksel RCSTA
bsf RCSTA, SPEN ; 0 Rx enable,
bsf RCSTA, CREN ; 0 continuous Rx,
return
; Output W to the UART.
serout banksel PIR1
__so1 btfss PIR1, TXIF ; Tx full
goto __so1 ; wait...
movwf TXREG ; output to transmitter.
return
schematic:
0 Comments:
Post a Comment
<< Home