Searching \ for '[PIC] 16f876a UART Help' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=16F
Search entire site for: '16f876a UART Help'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] 16f876a UART Help'
2005\04\18@102350 by Josh Koffman

face picon face
Hi all. I've just built a little 16f876a based surface mount board
with a MAX233 convertor. The idea is that I'm going to load it up with
a bootloader so I don't have to lug my programmer with me while I'm on
vacation next week (yes, I work during my vacations). I wrote up the
following little program to test that the RS232 connection is working.
I've never used a bootloader before, so I just wanted to verify my
hardware first. However, it isn't working. I've checked my circuit,
and I think I'm ok. I scope the TX line on my PIC and get no activity.
The program turns on port pins as it goes so I can see the progress,
and it seems to get caught in the loop waiting for PIR1, TXIF to go
high (porta,2 never gets set). So...I think I've done something funky
in software. The main guts of this program used to work on a non A
16f876. Maybe that's the key? I thought I had changed the relevant
bits. Maybe I should be looking for the TXSTA, TRMT bit instead of the
TXIF bit? Maybe I've done something stupid and forgotten a bank
switch?

Here is my code...I'd appreciate it if someone could have a look. I
know it isn't the best practice. It's in absolute mode, and it doesn't
use interrupts. Bank switching is messy. The main goal is just to sit
there spewing out data though. Here it is:



       LIST    R=DEC                ;  
       list P=PIC16F876a
       #include p16F876a.inc


               __CONFIG (_HS_OSC & _WDT_OFF & _CP_OFF & _LVP_OFF & _PWRTE_ON &
_BODEN_OFF )        ;  #### - Updated

Start_Vector               EQU     H'00'
Interrupt_Vector       EQU     H'04'
Ram_Base               EQU     H'20'
Common_Ram_Base        EQU     H'70'

Osc_Freq               EQU     D'16000000'

   CBLOCK Ram_Base
   temp  
   endc


;
; -----------
; DESCRIPTION
; -----------
;
; Baud Rate = 9600, No Parity, 8 bits & 1 Stop Bit
;
; -------------
; PROGRAM START
; -------------
;
   org     Start_Vector
   goto    Start
   

   org     Interrupt_Vector      
   goto    ISR_Start

ISR_Start
   retfie
   


Start
   bcf     status, rp0
   bcf     status, rp1
   clrf    PORTA               ; Clear the ports
   clrf    PORTB
   clrf    PORTC

   bsf     status, rp0         ; Bank 1

   movlw   b'01000110'         ; Setup ADC, All digital
   movwf   ADCON1^ 0x080    
   
   movlw   b'01011111'         ; PortB pullups on
   movwf   OPTION_REG^ 0x080    

   movlw   b'00000000'         ; Setup port directions
   movwf   TRISA^ 0x080
   movlw   b'00000000'
   movwf   TRISB^ 0x080
   movlw   b'11000000'         ; set RC6 & RC7 as input
   movwf   TRISC^ 0x080
   
   bcf     status, rp0         ; Bank 0


; Setup UART

   bsf     status, rp0         ; Bank 1

                   ;  Baud Values with BRGH = 1
                   ;  ((16000000/9600)/16)-1 = 103
   movlw   d'103'              ;  9600 baud @ 16 Mhz Fosc +0.16 err
   movwf   SPBRG^ 0x080
   movlw   b'00100100'         ; brgh = 1
   movwf   TXSTA^ 0x080               ; enable Async Transmission, set brgh

   bcf     status, rp0         ; Bank 0

; ------------------------------------
; PROVIDE A SETTLING TIME FOR START UP
; ------------------------------------
;
   clrf    temp
Settle
   decfsz  temp,f
   goto    Settle

   goto    Main
   
   
Main

       bsf                porta, 0
       movlw        b'10101010'
       movwf        PORTB


   movlw   b'00001010'
   movwf   portc

   movlw   'T'
   call    TXLoop
   movlw   'E'
   call    TXLoop
   movlw   'S'
   call    TXLoop
   movlw   'T'
   call    TXLoop
   movlw   ' '
   call    TXLoop
   goto    Main

TxLoop
   nop

       bsf                porta, 1

   movwf   TXREG

       nop
       nop

   btfss   PIR1,TXIF           ;xmit buffer empty?
   goto    TxLoop              ;no, wait


       bsf                porta, 2

   return

end

Thanks for reading this far!

Josh
--
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
       -Douglas Adams

2005\04\18@103612 by Byron A Jeff

face picon face
On Mon, Apr 18, 2005 at 10:23:49AM -0400, Josh Koffman wrote:

Josh,

I didn't even look at your code. The first consultation with all things
UART based is Fr. Thomas McGahee's PICUART tutorial. You can find it here:

http://www.pic101.com/mcgahee/picuart.zip

It has all the tips, tricks, and traps. It's also working code. So you
can just drop it in an test.

Start there. When it works, then you can compare against it to your code and
see where it went off the rails.

BAJ

2005\04\18@121512 by Josh Koffman

face picon face
Oh wait, I figured it out. Thanks for the link Byron...I was trying to
avoid Fr. Tom's work as it's so comprehensive, and I just needed a
simple test. That turned out to be the wrong move though. Forcing it
in my face made me read it, and sure enough, I remembered what I had
forgotten to do.

For those curious, I forgot to set the SPEN bit in RCSTA...kind of
important as it's the serial port enable bit. I didn't look at it
because all I wanted to test was the transmit function, and I always
associate RCSTA with receive. Stupid me.

Thanks again!

Josh
--
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
       -Douglas Adams

On 4/18/05, Byron A Jeff <spam_OUTbyronTakeThisOuTspamcc.gatech.edu> wrote:
{Quote hidden}

2005\04\18@125622 by phil B

picon face
I don't know if you've done this already but I'd first
verify the hardware before tearing into the software.
 two steps:
1) jumper Tx and Rx on your cable and see if your
terminal program echoes keystrokes. If not, check
cable and terminal program.
2) jumper Tx and Rx on the PIC side of the Max 233 and
then check to see if you get keystrokes echoed.  If
not, then your 233 is wired up wrong.

When you know the HW is good, then debuging the SW
makes sense.  I once spent about 2 hrs stepping
through serial I/O code before discovering that the
cable was faulty...  grrrr

Phil

--- Josh Koffman <.....joshybearKILLspamspam@spam@gmail.com> wrote:

{Quote hidden}

> --

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...