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.

help:ADC with PIC16F877A

Status
Not open for further replies.

darlling5147

New Member
i'm trying to built an ADC circuit by using PIC16F877A+MAX232+RS232. can anyone provide me the circuit diagram(schematic) of the ADC?
any related info is welcome to post up here....thx!!!!!

ur help is fully appreciate :)
 
darlling5147 said:
sorry,i jus new to here....mayb i missed it.....
thx for telling me

First look up the MAX232 datasheet to learn what each pin does and how to wire it up and such. Then you are going to have to read the PIC datasheet a LOT since uC datasheets are pretty big (unelss you already know how to use the PIC). Learn the wiring to program the PIC and such. Then worry about RS232 protocal (the rest is in software).

Biggest hardware things are at first are learning how to clock the PIC (either hook up a crystal oscillator or enable the PIC's internal clock with software) and wiring up to program the PIC. Plus, bypass capacitors across each IC's power supply to filter noise and such. The rest is "fairly" easy to hook up...like if you need to use a pin you can just probably connect it directly to whatever you need to.
 
Last edited:
darlling5147 said:
i'm trying to built an ADC circuit by using PIC16F877A+MAX232+RS232. can anyone provide me the circuit diagram(schematic) of the ADC?
any related info is welcome to post up here....thx!!!!!

ur help is fully appreciate :)

Check my tutorials, they include everything you need!.
 
try the circuit which i had previously...

Hi,

For Serial communication just follow thw cicuit in attachment and follow the hitech pic code, it will return a value what is received before. Sending ADC value to System not a big thing just read ADC part datasheet and simply follow it.

#include<pic.h>

void main()
{
unsigned char ReceiveChar;
TRISC=0xc0;
TXSTA=0x24;
SPBRG=25;
RCSTA=0x90;
TXREG='0';

while(1)
{

if (RCIF==1)
{
ReceiveChar=RCREG;
if (TXIF==1)
TXREG=ReceiveChar;
}
}
}
 

Attachments

  • MAX232.jpg
    MAX232.jpg
    18.6 KB · Views: 1,226
that code will work but expects a clock rate of 4Mhz for a 9.6K baudrate. look in the tables in the 877 datasheet USART section for your clock rate and desired baudrate. also, you may need an initial delay to let your max232's charge pump to get up to voltage.

kumar - could you post source with the code tags? it indents properly and is much more readable.
 
could you post source with the code tags? it indents properly and is much more readable.

This code will work for all Oscillators, without restriction b'coz there is no need to have an delay instead the code simply check whether the previous byte has been sent or not by checking the TXIF bit, if the TXIF bit is 1 then we can assume the previous byte has been sent and Transmit register TXREG is now ready to send next byte. IIIly if RCIF is 1 then we can assume there is a byte in RCREG.

#include<pic.h>

void main()
{
unsigned char ReceiveChar;
TRISC=0xc0; //Set RX and TX pin as input to enable serial communication
TXSTA=0x24; //Transmit Enable (TXEN=1) and Select high baud rate(BRGH=1) leave rest
SPBRG=25; //select baud rate 9600 by moving decimal 25 to SPBRG when BRGH=1
RCSTA=0x90; //Enable continuos receive and enable usart communication(SPEN=CREN=1)
TXREG='0'; //Sending a dummy character to initialize commn so at the end of last bit TXIF will be set to 1 or we can set TXIF to 1 to start sending bytes

while(1) //repeat the following forever
{

if (RCIF==1) //if character is received from PC
{
ReceiveChar=RCREG; //move the character to a variable
if (TXIF==1) //if TXREG is empty
TXREG=ReceiveChar; // send the same character to PC
}
}
}
 
sukumar said:
This code will work for all Oscillators, without restriction

No it won't! - it has EXACTLY the same restrictions as other methods, that it's set to a particular baud rate and a particular oscillator frequency. Where as with software RS232 you need to alter the delay time, in this case you need to alter the register values (which effectively set the delay time). Same thing really - but if you've got the hardware UART it's worth using, assuming the pin isn't being used elsewhere?.
 
Hi,

Yes ofcourse u r correct but what i am trying to say is :

For the same value ie decimal 25 we can get:
9600 baud rate at 16 MHz when brgh=0
9600 baud rate at 4 MHz when brgh=1
2400 baud rate at 4 MHz when brgh=0

so just changing the brgh and spbrg values is enough to work in different baudrates. Thats the thing i want to tell.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top