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.

doing a project in traffic light

Status
Not open for further replies.

hanukaran

Junior Member level 2
Joined
Oct 15, 2010
Messages
24
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,283
Activity points
1,542
this the c coding which i using to function the traffic light with using Atmega32.
Now i want to send to serial port with using max232 and rs232.
How to send the data if the red_1 is in "o" or "1"..Below the c coding i have visual basic programme to interface it...
i want the sent data to be shown in visual basic
can you help me

#include <mega32.h>
#include <delay.h>

#define red_1 PORTA.0
#define yellow_1 PORTA.1
#define green_1 PORTA.2
#define red_2 PORTA.3
#define yellow_2 PORTA.4
#define green_2 PORTA.5
#define green_a PORTA.6
#define red_a PORTA.7
#define green_b PORTB.0
#define red_b PORTB.1
#define tx PORTD.1
#define rx PORTD.0


unsigned char a,b;



unsigned char segment (unsigned char input){
switch(input){
case 1:{return 0x06;break;}
case 2:{return 0x5B;break;}
case 3:{return 0x4F;break;}
case 4:{return 0x66;break;}
case 5:{return 0x6D;break;}
case 6:{return 0x7D;break;}
case 7:{return 0x07;break;}
case 8:{return 0x7F;break;}
case 9:{return 0x6F;break;}
case 0:{return 0x3F;break;}
}
}

void delay_green(void){
red_a=0;
green_b=0;
a=9;
b=0;
while(b!=10){
delay_ms(1000);
b++;
PORTC=segment(a);
green_a=1;
red_b=1;
a--;
}
a=9;
}


void delay_red(void){
green_a=0;
red_b=0;
a=9;
b=0;
while(b!=10){

delay_ms(1000);
b++;
PORTC=segment(a);
red_a=1;
green_b=1;
a--;
}
}


void main(void){
PORTA=0x00;
DDRA=0xFF;
PORTB=0x00;
DDRB=0x03;
PORTC=0x00;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xFF;
UCSRA=0×00;
UCSRB=0×18;
UCSRC=0×86;
UBRRH=0×00;
UBRRL=0×33;


while (1)
{
red_1=0;
if (red_1=1)
PORTD.1 = 1;
}
else {
return red_2
};

red_2=1;
green_1=1;
delay_green();
green_1=0;
yellow_1=1;
delay_ms(1500);
yellow_1=0;
red_1=1;
red_2=0;
green_2=1;
delay_red();
yellow_2=1;
green_2=0;
delay_ms(1500);
yellow_2=0;
};
}







This is my Visual basic interface programme for using parallel port....
how to modify so that can connect to serial port rs 232...which part have to modify in programme?




Option Explicit ' declaration on all the input and output file
Private Declare Function Inp32 Lib "Dllport.dll" (ByVal portaddress As Integer) As Integer
Private Declare Sub Out32 Lib "Dllport.dll" (ByVal portaddress As Integer, ByVal value As Integer)
Dim mydate As Date

Private Sub Command1_Click()
Timer1.Interval = 0
Timer2.Interval = 0

End Sub

Private Sub Command2_Click()
Timer1.Interval = 500
Timer2.Interval = 100
End Sub

Private Sub Command3_Click()
Unload Me
form4.Show

End Sub

Private Sub Form_Load()

Shape1.Visible = False
Shape3.Visible = False
Shape5.Visible = False
Shape2.Visible = True
Shape4.Visible = True
Shape6.Visible = True
End Sub


Private Sub Timer1_Timer()
Label1.Caption = (Inp32(&H379)) And 8
Label2.Caption = (Inp32(&H379)) And 16
Label3.Caption = (Inp32(&H379)) And 32
Label4.Caption = (Inp32(&H379)) And 64


If Label1.Caption = 8 Then 'the red light
Shape2.Visible = True
Shape1.Visible = False
Label11.Caption = "OK"
ElseIf Label1.Caption = 0 Then
Shape2.Visible = False
Shape1.Visible = True
Label11.Caption = "ERROR"
Beep
End If

If Label2.Caption = 16 Then 'the orange light
Shape4.Visible = True
Shape3.Visible = False
Label16.Caption = "OK"
ElseIf Label2.Caption = 0 Then
Shape4.Visible = False
Shape3.Visible = True
Label16.Caption = "ERROR"
Beep
End If

If Label3.Caption = 32 Then 'the green light
Shape6.Visible = True
Shape5.Visible = False
Label17.Caption = "OK"
ElseIf Label3.Caption = 0 Then
Shape6.Visible = False
Shape5.Visible = True
Label17.Caption = "ERROR"
Beep
End If

If Label4.Caption = 64 Then 'the fault 1
Label10.Caption = "OK"
ElseIf Label4.Caption = 0 Then
Label10.Caption = "ERROR"
Beep
End If

'Send the input to output data line
If Label1.Caption = 8 Then Out32 &H378, 1 'the output of red light
If Label2.Caption = 16 Then Out32 &H378, 2 'the output of orange light
If Label3.Caption = 32 Then Out32 &H378, 4 'the output of green light
If Label4.Caption = 64 Then Out32 &H378, 8 'the output of fault 1
End Sub

Private Sub Timer2_Timer()

Label7.Caption = Date 'system date
Label8.Caption = Time 'system date
mydate = Format(Label7.Caption, "D - MMMM - YY") 'system date
Label9.Caption = Format(mydate, "dddd")
End Sub


can any one help..i really need assistance..thanks for your valuable time
 

PD0 and PD1 pins from PORTD are dedicated for USART... Through TXD and RXD u can Transmit and Receive the data...
This is the c code for USART initialization...

void USART_Init( unsigned int baud )
{
/* Set baud rate */
UBRRH = (unsigned char)(baud>>8);
UBRRL = (unsigned char)baud;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}

---------- Post added at 09:56 ---------- Previous post was at 09:55 ----------

Sorry .... 8 will come in the place of smiley...
 
i have modify the coding....can you suggest me to improve

#include <mega32.h>
#include <delay.h>

#define red_1 PORTA.0
#define yellow_1 PORTA.1
#define green_1 PORTA.2
#define RXD PORTD.0
#define TXD PORTD.1

void USART_Init( unsigned int baud )
{
/* Set baud rate */
UBRRH = (unsigned char)(baud>>8;
UBRRL = (unsigned char)baud;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}

void main(void){
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);
};
}
 

i attach the schematic file,the rs232 and visual basic n c coding for Atmega....

now i change the two way traffic to 1 way...the program look like below....


#include <mega32.h>
#include <delay.h>

#define red_1 PORTA.0
#define yellow_1 PORTA.1
#define green_1 PORTA.2

void main(void){
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);
};
}

now when the red_1=0 and for every led.......i want microcontroller send information to rs232 and lastly to visual basic......in basic visual should show that red is off...
how to create coding so that i can upload in microcontroller.....
ho
 

Attachments

  • project.rar
    164.2 KB · Views: 109

This c code is used 2 transmit character through RS232....

void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) );
/* Put data into buffer, sends the data */
UDR = data;
}
 

BUT SIR IF I PUT LIKE THIS...THERE IS ERROR
Error: Trafic light.c(18): undefined symbol 'USBS'
Error: Trafic light.c(21): undefined symbol 'RXEN'
Error: Trafic light.c(29): undefined symbol 'UDRE'
Error: Trafic light.c(37): undefined symbol 'RXC'
AFTER i solve that 4 with define like BELOW

than again come some more undefined symbol such TXEN,RXEN ,RXC ,URSEL AND SO ON..BUT AFTER IDEFINE ALL THIS..THERE IS NO ERROR.
iS THAT I SHOULD DEFINE...OR SOMETHING I DID WRONG SO MAKE ERROR....
#define UCSZ0 1
#define UCSZ1 2
#define USBS 3
#define URSEL 7
#define UDRE 5
#define TXC 6
#define RXC 7
#define TXEN 3
#define RXEN 4

COULD ANYONE HELP ME...IM USING CODEVISION AVR
 

#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>

Like this You have to include basic header files... If you check in external dependency [Left hand side of AVR studio {AVR GCC}] there avrlibdefs.h, common.h, eeprom.h, fuse.h, interrupt.h, inttypes.h, io.h, iom32.h, lock.h, portpins.h, sfr_defs.h, stddef.h, stdint.h, version.h, wdt.h.... Like these you can see lot dependent library files... Not exact these file... For example i have included all the files.... If these files included means you will not get errors above what you said..
 

ir i have error after compile in avr studio..i dnt have idea. please sir help me to correct my mistakes
this is my errors:

avr-gcc -mmcu=atmega32 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT praba.o -MF dep/praba.o.d -c ../praba.c
../praba.c:11: warning: return type of 'main' is not 'int'
../praba.c: In function 'main':
../praba.c:56: error: expected ';' before numeric constant
../praba.c:57: error: expected ';' before numeric constant
../praba.c:58: warning: implicit declaration of function 'delay_ms'
../praba.c:59: error: expected ';' before numeric constant
../praba.c:60: error: expected ';' before numeric constant
../praba.c:62: error: expected ';' before numeric constant
../praba.c:63: error: expected ';' before numeric constant
../praba.c:70: error: expected ')' before numeric constant
../praba.c:72: error: expected ';' before numeric constant
../praba.c:75: error: expected ')' before numeric constant
../praba.c:77: error: expected ';' before numeric constant
../praba.c:80: error: expected ')' before numeric constant
../praba.c:82: error: expected ';' before numeric constant
make: *** [praba.o] Error 1
Build failed with 12 errors and 2 warnings...






#include <avr/io.h>
#define red_1 PORTA.0
#define yellow_1 PORTA.1
#define green_1 PORTA.2


void main(void){
PORTA=0x00;
DDRA=0xFF;
PORTB=0x00;
DDRB=0x03;
PORTC=0x00;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xFF;




void USART_init(unsigned int ubrr)
{
//set baud rate
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;

//Enable receiver and transmitter
UCSRB = (1<<RXEN)|(1<<TXEN);

//set frame format: 8 data, 1 stop bit
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
}

void USART_Transmit(unsigned char data)
{
//wait for empty transmit buffer
while(!(UCSRA & (1<<UDRE))==0);

//put data into buffer, sends the data
UDR = data;
}
unsigned char USART_Receive(void)
{
//wait for data to be received
while(!(UCSRA & (1<<RXC))==0);

//get and return received data from buffer
return UDR;
}

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;
USART_Transmit('G');
}
if(green_1==0)
{
yellow_1=1;
USART_Transmit('Y');
}
if (yellow_1==0)
{
red_1=1;
USART_Transmit('R');
} }



}
 

I want to know Which port pins you are using as a input and which port pins are using as a output... Here Port A.0 you are using as a both input as well as output without changing a configurations... could send me your exact requirement to my mail id... Then we will discuss... Here library functions are there for setting a bit as well as clearing a bit... sbi(port, bit) for setting a bit and cbi(port, bit) for clearing a bit...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top