Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Connect the interface over J2 of MCBX51 adapter */
- /* This program simutaes the traffic light */
- #include<stdio.h>
- #include <REG51RD2.H>
- void delay(int k);
- unsigned char xdata control _at_ 0xe003;
- unsigned char xdata porta _at_ 0xe000;
- unsigned char xdata portb _at_ 0xe001;
- unsigned char xdata portc _at_ 0xe002;
- unsigned char code str[31]={0x10,0x81,0x7a,
- 0x44,0x44,0xf0,
- 0x8,0x11,0xe5,
- 0x44,0x44,0xf0,
- 0x81,0x10,0xda,
- 0x44,0x44,0xf0,
- 0x11,0x8,0xb5,
- 0x44,0x44,0xf0,
- 0x88,0x88,0x00,
- 0x44,0x44,0xf0,
- 0x00
- };
- void traffic_s();
- void traffic_n();
- void traffic_se();
- void reset();
- void main()
- {
- control = 0x80;
- portb=0x00;
- porta=0x0f;
- portc=0xf0;
- /*//all predestian red
- portc = 0xd0;
- //west red
- portb = 0x80;
- traffic_n();
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- traffic_s();
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- delay(30000);
- traffic_se();*/
- }
- void traffic_s()
- {
- //south red
- porta = 0x08;
- //north s green
- portc = portc + 0x02;
- }
- void traffic_n()
- {
- reset();
- //north red
- portb = portb + 0x08;
- // south s green
- portc = portc + 0x08;
- }
- void traffic_se()
- {
- reset();
- //south red
- porta = 0x08;
- //east left green
- porta = porta + 0x10;
- }
- void reset()
- {
- //all predestian red
- portc = 0xd0;
- //west red
- portb = 0x80;
- }
- void delay(int k)
- {
- int p;
- for(p=0;p<=k;p++)
- {
- ;
- }
- }
Add Comment
Please, Sign In to add comment