闲极无聊,做了个LED免限流电阻直接驱动实验,效果不错
/*************************************************
工程名:LED免限流电阻直接驱动实验
作 者:老芹
定时器每0.5mS中断一次,八位显示耗时12mS,每位1.5mS
CPU:STC15F204EA
验证通过
************************************************/
#include <STC15F2K60S2.H>
typedef unsigned char uint8;
typedef unsigned int uint16;
uint8 Timer_1,IO_control; //LED_control作为控制LED亮灭的控制变量
sbit LED = P2^5;
void Timer0_Init();
void IO_Model_Config(); //初始化IO口
void main()
{
Timer0_Init();
IO_Model_Config(); //IO工作模式配置(将LED的IO设置为推挽输出模式)
while(1)
{
}
}
void Timer0() interrupt 1 //定时器中断 ,16位自动重装模式,无需重赋初值
{
Timer_1++;
LED = IO_control;
if (Timer_1<=3)
IO_control = 1;
else IO_control = 0;
if (Timer_1==12)
Timer_1 = 0;
}
void Timer0_Init() //定时器初始化
{
AUXR &= 0x7F; //定时器时钟12T模式,0.5mS
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x33; //设置定时初值
TH0 = 0xFE; //设置定时初值
TR0 = 1; //定时器0开始计时
ET0 =1;
EA = 1;
}
void IO_Model_Config()
{
P2M1 = 0x00;
P2M0 = 0xff;
}
|