PDA

View Full Version : byte Tx w/ USART 16f876a problem



GargamelDigi
- 10th July 2008, 23:50
Ok I searched through this site and can't find a solid answer. I did find a lot of usefull info to get me to this point though.

I am gettign an output but is just not the byte I try to send. The PWREN# bit is coming from a FT232R chip from FTDI which is a USB bridge.

I am using picbasic, and the code is:

Symbol TRISA = $85
Symbol PORTA = $05
Symbol TRISB = $86
Symbol PORTB = $06
Symbol TRISC = $87
Symbol PORTC = $07
Symbol ADCON1 = $9F ' A/D Control Register 1
Symbol ADCON0 = $1F ' A/D Control Register 0

' Define the USART registers
Symbol PIR1 = $0C ' Peripheral Interrupt Flag register
Symbol RCSTA = $18 ' Receive Status and Control register
Symbol TXREG = $19 ' Transmit Data register
Symbol RCREG = $1A ' Receive Data register
Symbol TXSTA = $98 ' Transmit Status and Control register
Symbol SPBRG = $99 ' Baud Rate Generator register

init:

Poke ADCON1, 6 ' Set all PortA to digital I/O
Poke ADCON0, 5 ' Set all PortB to digital I/O
Poke TRISB, %00000000
Poke TRISA, %11111111 ' sets "1" to input,"0" output

' Initialize USART
Poke TRISC, %10111111 ' Set TX (PortC.6) to out, rest in
Poke SPBRG, 25 ' Set baud rate to 9600 (4MHz clock)
Poke RCSTA, %10010000 ' Enable serial port and continuous receive
Poke TXSTA, %00100000 ' Enable transmit and asynchronous mode


usart:

Peek PORTA, b0
IF bit0 = 0 Then main ' usb PWREN# bit

GoTo usart

main:

Poke PORTB, %01000000

Peek PORTA, b0
IF bit1 = 0 Then tx ' when button is pressed Tx one byte

GoTo main



tx:

b0 = 0

Peek PIR1, b0
IF bit4 = 0 Then tx

Poke TXREG, $7A ' byte to send over Tx

Poke PORTB, %01110000 ' flash two LED's when Tx
Pause 300
Poke PORTB, %01000000

GoTo main


Any help will be very appreciated! Been stuck on this all day!

Thank you in advanced

skimask
- 14th July 2008, 17:56
Are you 100% sure about those ADCON register settings?
How about the Comparator Module register settings?

GargamelDigi
- 15th July 2008, 05:50
from some other help I received Poke ADCON0 should not be neccessary.

Poke ADCON1 in the data sheet says 011x for all pins, so this equals 6 or 7 with the x.

I have no problem reading the port a or port b, I just can't get anything to be sent out the USART Tx. When I send (or try to) the LED's flash with the button push just no data goes over Tx. The scope shows a constant 5v.

Thanks,
Jeremy