Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

UART on 16F627A not working!!!

Status
Not open for further replies.

threewire

New Member
Hi,

I have been trying to get UART code running on 16F627A.This is my first time with PIC.I got the LED blinking at two different Hz.Hence I confirm that 20 Mhz crystal is set by setting config to 3FA6.I have used 15 pf capacitors.My max232 with USB converter is working fine.But I am not able to get UART working on 16F627A.Please help.

I used the mikroC compiler's UART example.
 
You must post your code examples when you asking code problems.


UART example code as given in MikroC is :
Code:
unsigned short i;

void main() {
   USART_init(9600);                     // initialize USART module
                                          //  (8 bit, 19200 baud rate, no parity bit...)
   while (1) {
     if (USART_Data_Ready()) {            // if data is received
       i = USART_Read();                  // read the received data
       USART_Write(i);                    // send data via USART
       }
     }
}

Code:
config bits :

pwrt = on
mclr = off
hs_osc = on
wdt = on
lvp = off
 
Hi, 3W

looks You do become an "afficionado" ...

may I suggest you a little mod ' ???

Code:
unsigned short i;

void main() {
   USART_init(9600);                     // initialize USART module
                                          //  (8 bit, 19200 baud rate, no parity bit...)
   while (1) {
     if (USART_Data_Ready()) {            // if data is received
       i = USART_Read();                       // read the received data
       USART_Write(i + 1);                    // send data via USART
       }
     }
}

Does it still do not work ??? ...

"your" program works fine aboard my EasyPic5 with a '628 ( no 627 home ...)

Alain
 
Hi Alain,

I dont think it is with this piece of code.I think it might be with the bits (config bits setting) for the 16F627A.

I have set PWRT_ON ,WDT_ON ,HS_OSC,LVP_OFF,MCLR_OFF for 16F627A and at 20 Mhz clock.(By the way I am using 22pf caps with the 20 Mhz xtal).

Just changing the variale "i" to "i+1" may not do the thing.I even checked it in the terminal no characters get echoed back not even stray characters.So what could be the problem.(But I will try as you said if something turns out).
 
Probably YES ...

But why did you change that ??? it was already set to OFF in MkC example ...

the +1 was added because ,@ first , I didn't know if the character shown was due to Hyperterm or the Pic ... ( you'll see what I mean ...)

Alain
 
I set WDT=OFF but still the PIC does not echo back.

Sorry, I don't do C - it's a trivial program to do in assembler though.

Any idea as to what could be the problem?Does the capacitance values on Max232 change from micro to micro.Max232 circuit is working fine with

Makes no difference, the capacitors are VERY non-critical.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top