hanukaran
Junior Member level 2
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
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