Maverickmax
Advanced Member level 1
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
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);
}
}