中颖单片机实现流水灯的源码如下:- /********************************************************************************************************
- 说明: 使用了外部中断4,定时器中断1,实现了跑马灯程序
- 本程序通过按键S1改变LED灯工作的数量,按键S2改变LED灯闪烁的频率,实现跑马灯的效果
- 要求:打开拨码开关J8
- *********************************************************************************************************/
- #include <sh88f516.h>
- unsigned char Num,Fnum;
- unsigned char Disp;
- unsigned char Time0Count;
- bit DispFlag;
- void mcu_init();
- main()
- {
- mcu_init();
- while(1)
- {
- if(DispFlag)
- {
- DispFlag = 0;
- P0 = (P0&0xFC) | (Disp&0x03); //端口0的低2位对应LED灯的D2 D3
- P1 = (P1&0x03) | (Disp&0xFC); //端口1的高6位对应LED灯的D4-D9
- Disp <<= 1;
- if(CY)
- Disp |= 0x01;
- }
- }
- }
- void mcu_init()
- {
- CLKCON = 0x60; //系统频率=晶振频率/12
- P0M0 = 0x00;
- P0M1 = 0xFF; //推挽输出模式
- P1M0 = 0x00;
- P1M1 = 0xFF; //推挽输出模式
- IENC = 0x70; //0111 0000 外部中断4的选择寄存器,1-打开,0-关闭
- EXF0 = 0x80; //上升沿触发
- TH0 = 0xFA;
- TL0 = 0x00;
- TMOD = 0x01; // Timer 0 is 16-bit counter, timer mode
- ET0 = 1; //enable timer 0 interrupt
- TR0 = 1; //enable timer 0
- IEN1 = 0x40; //ELPD EX4 EPWM ESCM ECMP1 ES1 ECMP0 ESPI 0100 0000
- EA = 1; //开启总中断
- Num = 0;
- Fnum = 4;
- DispFlag = 1;
- P0 = 0;
- P1 = 0;
- P2 =P2 |0x80;
- Disp = 0x01;
- }
- void Timer0_int() interrupt 1
- {
- Time0Count++;
- if(Time0Count>=Fnum)
- {
- Time0Count = 0;
- DispFlag = 1;
- }
- }
- void EX4_INT() interrupt 13 //using 2 //外部中断4的中断号为13.
- {
- IEN1 &= 0xBF;
- if(IF45) //P2.5对应于板子上的S2
- {
- Fnum--;
- if(Fnum==0)
- Fnum = 6;
- }
- if(IF46) //P2.6对应于板子上的S1
- {
- Num++;
- if(Num==5)
- Num = 0;
- switch(Num)
- {
- case 0: Disp = 0x01;
- break;
- case 1: Disp = 0x03;
- break;
- case 2: Disp = 0x0F;
- break;
- case 3: Disp = 0x11;
- break;
- case 4: Disp = 0x55;
- break;
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
[color=rgb(51, 102, 153) !important]复制代码
压缩包里面包含有中颖单片机sh88f516常用功能的源码,中文注释都很详细
下载地址:http://www.51hei.com/bbs/dpj-98300-1.html
|