蓝桥杯基础功能练习程序
单片机源程序如下:
- #include "reg52.h"
- sbit L0=P0^0;
- sbit S7=P3^0;
- unsigned char count=0,fun=0,PWM;
- void SelectHC573(unsigned char n)
- {
- switch(n)
- {
- case 4:P2=P2&0x1f|0x80;break;
- case 5:P2=P2&0x1f|0xa0;break;
- case 6:P2=P2&0x1f|0xc0;break;
- case 7:P2=P2&0x1f|0xe0;break;
- }
- }
- void ZDsurvice_timer0()
- {
- TMOD=0x01;
- ET0=1;
- EA=1;
- TH0=(65536-100)/256;
- TL0=(65536-100)%256;
- }
- void ZD_timer0() interrupt 1
- {
- TH0=(65536-100)/256;
- TL0=(65536-100)%256;
- count++;
- if(count==PWM)
- {
- L0=1;
- }
- if(count==100)
- {
- count=0;
- L0=0;
- }
- }
- void delay(unsigned char t)
- {
- while(t--);
- }
- void scan_key()
- {
- if(S7==0)
- {
- delay(100);
- if(S7==0)
- {
- while(S7==0);
- switch(fun)
- {
- case 0:PWM=10;TR0=1;fun=1;break;
- case 1:PWM=50;fun=2;break;
- case 2:PWM=90;fun=3;break;
- case 3:L0=1;TR0=0;fun=0;break;
- }
- }
- }
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
蓝桥杯练习程序.rar
(10.58 KB, 下载次数: 15)
|