Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8051 with ADC conversion and RS232 code

Status
Not open for further replies.

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,689
rs232 code

Hi

I have been trying to make my microcontroller to send data to hyperterminal but nothing happened. Im not 100 percent entirely sure if my code cause the problem. So can you please kindly check my code for any errors?

Cheer

MavericK Max

Code:
// header files
#include "main.h"
#include "port.h"
#include "delay_loop.h"

int result_G;

void serial_init();
void send_serial(unsigned char *s);
void send_1_char(unsigned char c);

void initialize();      
void start_conversion();

//interrupt1() interrupt 2

void serial_init()
{
    SCON=0x50;        //Setup for 8-bit data
    TMOD=0x20;        //Setup timer 1 for auto-reload
    TH1=0xF3;        //Setup for 2400 Baud
    TR1=1;            //Turn on timer 1
    TI=1;            //Indicate ready to transmit
}


void send_serial(unsigned char *s)
{
    while(*s !=0x00)
    {
        SBUF=*s;
        while(! TI)
        {

        }
        TI=0;

        s++;
    }
}


void send_1_char(unsigned char c)
{
     SBUF=c;
    while(! TI)
    {

    }
    TI=0;
}


void initialize()
{
     ADC_RD=1;
    ADC_WR=1;
    IT1=1;
    EX1=1;
    EA=1;
}


void start_conversion()
{
     ADC_WR=0;
    ADC_WR=1;
}

interrupt1() interrupt 2
{
     ADC_RD=0;
    result_G=DATA;

    ADC_RD=1;
    send_1_char(result_G);
    Delay_Loop(100);
    start_conversion();
}

void main(void)                                  
{
    unsigned char crlf[]={0x0D,0x0A,0x00};
    serial_init();
    send_serial(crlf);
    send_serial("--------------------------------");
    send_serial(crlf);
   

    initialize();
    start_conversion();                         

    while(1)
    {
        LED=ON;
        Delay_Loop(25);
      LED=OFF;
        Delay_Loop(25);
    }
   

}
 

8051 adc code

What is the crystal frequency? Is the timer reload value correct for the crystal and baud rate you are considering?

I generally configure UART with double baud-rate by setting bit in PCON. You might have missed that!
Code:
	PCON |= 0x80;         // Double Baud Rate
	SCON  = 0x50;         // SCON: mode 1, 8-bit UART, enable rcvr
	TMOD |= 0x20;         // TMOD: timer 1, mode 2, 8-bit reload
	TH1   = BAUD_CONST;         // TH1:  reload value
	TL1   = BAUD_CONST;
	TR1   = 1;            // TR1:  timer 1 run
	TI    = 1;
	RI    = 0;
 

configure adc 8052

Hi

Im using 11.0592MHz crystal for my microcontroller chip......

Basically it work when I configured my code to print simple text on screen but I could not get data from ADC appear on the screen.

Im going to include the PCON in my codes now

Will back asap

Maverick Max
 

1. TH1=0xF3; //Setup for 2400 Baud
For 2400 baud at 11.0592MHz crystal the proper reload value is 0xF4. See the "bible" and Keil's baudrate calculator http://www.keil.com/c51/baudrate.asp

2. If you set TI=1 in initialisation and then don't wait for it in send_serial _before_ sending the character, you will lose one of the first two bytes you try to send

3. **broken link removed**

wek
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top