hanukaran
Junior Member level 2
can anyone help me to correct this coding so that i can send the data to PC through rs232...pls..Im doing project traffic light.
#include <mega32.h>
#include <delay.h>
#include <stdlib.h>
#define red_1 PORTA.0
#define yellow_1 PORTA.1
#define green_1 PORTA.2
#define USBS 3
#define RXEN 4
#define TXEN 3
#define UCSZ1 2
#define UDRE 5
#define UCSZ0 1
#define RXC 7
void USART_Init(unsigned short int F_CPU_MHz, unsigned short int Baud_Rate)
{
F_CPU_MHz= 8 ; ---> Remove this line
Baud_Rate= 9600 ;--> Remove this line
UCSRB = 0x00; // Disable while setting baud rate
UCSRA = 0x00; // Disable USART flags
UCSRC = (1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0); // 8-Bit data, 1-Bit Stop
UBRRL = ((F_CPU_MHz*1000000)/Baud_Rate/16)-1; // Set Baud Rate Lo - Asynch Normal Mode
UBRRH = 0x00; // Set Baud Rate Hi
UCSRB = (1<<RXEN)|(1<<TXEN); // Enable USART TX and RX
}
void Send_Byte(char data)
{
while ((UCSRA & (1<<UDRE)) == 0);
UDR = data;
}
char Receive_Byte(void)
{
while((UCSRA&(1<<RXC)) == 0);
return UDR;
}
void main(void){
USART_Init(8,9600);
PORTA=0x00;
DDRA=0xFF;
PORTB=0x00;
DDRB=0x03;
PORTC=0x00;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xFF;
while (1)
{
red_1=0;
green_1=1;
delay_ms(1500);
green_1=0;
yellow_1=1;
delay_ms(1500);
yellow_1=0;
red_1=1;
delay_ms(1500);
};
while(1)
{
if (red_1==0)
{
green_1=1;
Send_Byte('G');
}
if(green_1==0)
{
yellow_1=1;
Send_Byte('Y');
}
if (yellow_1==0)
{
red_1=1;
Send_Byte('R');
}}
}
#include <mega32.h>
#include <delay.h>
#include <stdlib.h>
#define red_1 PORTA.0
#define yellow_1 PORTA.1
#define green_1 PORTA.2
#define USBS 3
#define RXEN 4
#define TXEN 3
#define UCSZ1 2
#define UDRE 5
#define UCSZ0 1
#define RXC 7
void USART_Init(unsigned short int F_CPU_MHz, unsigned short int Baud_Rate)
{
F_CPU_MHz= 8 ; ---> Remove this line
Baud_Rate= 9600 ;--> Remove this line
UCSRB = 0x00; // Disable while setting baud rate
UCSRA = 0x00; // Disable USART flags
UCSRC = (1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0); // 8-Bit data, 1-Bit Stop
UBRRL = ((F_CPU_MHz*1000000)/Baud_Rate/16)-1; // Set Baud Rate Lo - Asynch Normal Mode
UBRRH = 0x00; // Set Baud Rate Hi
UCSRB = (1<<RXEN)|(1<<TXEN); // Enable USART TX and RX
}
void Send_Byte(char data)
{
while ((UCSRA & (1<<UDRE)) == 0);
UDR = data;
}
char Receive_Byte(void)
{
while((UCSRA&(1<<RXC)) == 0);
return UDR;
}
void main(void){
USART_Init(8,9600);
PORTA=0x00;
DDRA=0xFF;
PORTB=0x00;
DDRB=0x03;
PORTC=0x00;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xFF;
while (1)
{
red_1=0;
green_1=1;
delay_ms(1500);
green_1=0;
yellow_1=1;
delay_ms(1500);
yellow_1=0;
red_1=1;
delay_ms(1500);
};
while(1)
{
if (red_1==0)
{
green_1=1;
Send_Byte('G');
}
if(green_1==0)
{
yellow_1=1;
Send_Byte('Y');
}
if (yellow_1==0)
{
red_1=1;
Send_Byte('R');
}}
}