/***52单片机,12MHz晶振,P0-P3 接32颗LED,低电平驱动***/
#include"REG52.h"//包团派含52头文件
#define FALSE 0//定义布尔量'0':假
#define uchar unsigned char//定塌烂贺义 无符号字符型数历配据 简称
#define uint unsigned int//定义 无符号整型数据 简称
#define th0 0xb1
#define tl0 0xe0//20ms at 12MHz Fosc in Model 1
#define LED_Port1 P0
#define LED_Port2 P1
#define LED_Port3 P2
#define LED_Port4 P3
#define LED_AllOff LED_Port1=LED_Port2=LED_Port3=LED_Port4=0xff
#define LED_AllOn LED_Port1=LED_Port2=LED_Port3=LED_Port4=0
#define LED_Status 43//1步全亮+32步单亮+10步闪烁
#define LED_Marquee 32
bit T20msFlag=0
void Timer0() interrupt 1
{
TL0=tl0
TH0=th0
T20msFlag=TRUE
}
void TimerInit()
{
TMOD=0x01
TH0=th0
TL0=tl0
TR0=1
ET0=1
EA=1
}
void LED_Out()
{
static uchar led_status=0
if(T20msFlag)
{
T20msFlag=FALSE
led_status=++led_status%LED_Status
}
if(led_status &&led_status<=LED_Marquee)
{
LED_AllOn
switch((led_status-1)>>3)
{
case 0:LED_Port1=1<<((led_status-1)%8)break
case 1:LED_Port2=1<<((led_status-1)%8)break
case 2:LED_Port3=1<<((led_status-1)%8)break
case 3:LED_Port4=1<<((led_status-1)%8)break
default:led_status=0break
}
}
else
{
if(!led_status &&led_status%2) LED_AllOn
else LED_AllOff
}
}
void main()
{
TimerInit()
while(1)
{
LED_Out()
}
}
void RCC_Configuration(void)void NVIC_Configuration(void)
是时钟和逗做中断的配置函数声明,如果你确定你在该文件中没有使用就可以去掉
延时子团指程序延时长短取决于传塌指配送过来的参数nCount ,以及STM32的时钟及分频情况
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)