![]() |
附部分程序 #include <reg52.h> #define uint unsigned int #define uchar unsigned char sbit sta = P1 ^ 2; // Æô¶ˉ sbit bac = P1 ^ 3; // ·′Ïò sbit pwma = P1 ^ 4; // Õ¼¿Õ±è¼õ sbit pwms = P1 ^ 5; // Õ¼¿Õ±è¼ó sbit pwm = P3 ^ 7; uint number = 0; uint Zhan = 50; uint Flag = 0; void Delay_1ms(uint x) { uint i; uint j; for (i = 0; i < x; i++) for (j = 0; j < 148; j++); } void Timer0Init() { TMOD = 0x01; ET0 = 1; EA = 1; TH0 = (65536 - 100) / 256; TL0 = (65536 - 100) % 256; TR0 = 1; } void main() { Timer0Init(); P3 = 0xFF; while (1) { if (sta == 0) { Delay_1ms(200); P3 = 0xFE; Flag = ~Flag; } if (bac == 0) { Delay_1ms(200); P3 = ~P3; } if (pwma == 0) { Delay_1ms(100); Zhan++; } if (pwms == 0) { Delay_1ms(100); Zhan--; } if (Flag == 0) { P3 = 0xFF; } if(Zhan>100) Zhan=0; } } |