#include
#include
#include
unsigned int hour,minute,second,count;
sbit RS = P2^4;//Pin4
sbit RW = P2^5; //Pin5
sbit E
sbit BLCtrl = P2^7;
sbit KEY = P3^2;
#define Data
char data TimeNum[]="
char data Test1[]="
void DelayUs(unsigned char us)//delay us
{
}
void DelayMs(unsigned char ms)//delay Ms
{
}
void WriteCommand(unsigned char c)
{
}
void WriteData(unsigned char c)
{
}
void ShowChar(unsigned char pos,unsigned char c)
{
}
void ShowString (unsigned char line,char *ptr)
{
}
void InitLcd()
{
}
/////////////////////////////////////////////////////////////////
void main(void)
{
InitLcd();//初始化液晶
DelayMs(15);
sprintf(Test1," www.haotun.com ");//第一行
ShowString(0,Test1);
sprintf(TimeNum,"LCM1602 Test ok!");//第二行
ShowString(1,TimeNum);
while(1){
if(!KEY)
}
}
9.步进电机控制
#include
unsigned char code F_Rotation[4]={0x02,0x04,0x08,0x10};//正转表格
unsigned char code B_Rotation[4]={0x10,0x08,0x040,0x02};//反转表格
void Delay(unsigned int i)//延时
{
}
main()
{
}
10. 直流电机调速
#include
sbit KEY1 = P3^1;
sbit PWM = P1^5;
unsigned char CYCLE; //定义周期 该数字X基准定时时间 如果是10 则周期是10 x 0.1ms
unsigned char PWM_ON ;//定义高电平时间
void delay(unsigned int cnt)
{
}
main()
{
unsigned char PWM_Num;//定义档位
TMOD |=0x01;//定时器设置 1ms in 12M crystal
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;//定时1mS
IE= 0x82;
TR0=1;
CYCLE = 10;// 时间可以调整 这个是10步调整 周期10ms 8位PWM就是256步
while(1)
if(!KEY1)
}
void tim(void) interrupt 1 using 1
{
static unsigned char count; //
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;//定时1mS
if (count==PWM_ON)
if(count == CYCLE)
}
11.秒表
#include
code unsigned char tab[]=
unsigned char Dis_Shiwei;//定义十位
unsigned char Dis_Gewei; //定义个位
unsigned char S_Dis_Shiwei;//定义秒十位
unsigned char S_Dis_Gewei; //定义秒个位
unsigned char second,msecond;
void CLR(void);
void delay(unsigned int cnt)
{
}
main()
{
EX0=1;//外部中断0设置
IT0=1;
EX1=1;//外部中断1设置
IT1=1;
TMOD |=0x01;//定时器设置 10ms in 12M crystal
TH0=0xd8;
TL0=0xf0;
ET0=1;
TR0=0;
EA=1;
CLR();
while(1)
}
void tim(void) interrupt 1 using 1
{
TH0=0xd8;//重新赋值
TL0=0xf0;
msecond++;
if (msecond==100)
}
void ISR_INT0(void) interrupt 0 using 1
{
}
void ISR_INT1(void) interrupt 2 using 1
{
if(TR0==0)//停止时才可以清零
}
void CLR(void)
{
}
12.花样灯
#include
unsigned char code seg[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0x00,0,0x55,0x55,0xaa,0xaa};//rom允许情况可以无限添加
////////////////////////////////////////////////////////
void delay(unsigned int cnt)//简易延时
{
}
///////////////////////////////////////////////////////
main()
{
////////////////////////////////////
}
13.红绿灯
#include
bit red,green,yellow,turnred;
code unsigned char tab[]=
unsigned char Dis_Shiwei;//定义十位
unsigned char Dis_Gewei; //定义个位
void delay(unsigned int cnt)
{
}
main()
{
TMOD |=0x01;//定时器设置 10ms in 12M crystal
TH0=0xd8;
TL0=0xf0;
IE= 0x82;
TR0=1;
P1=0xfc;//红灯亮
red =1;
while(1)
}
void tim(void) interrupt 1 using 1
{
static unsigned char second=60,count; //初值99
TH0=0xd8;//重新赋值
TL0=0xf0;
count++;
if (count==100)
}
上一篇:单片机C语言程序举例(一)
下一篇:松翰单片机 RTC 应用注意
推荐阅读最新更新时间:2024-03-16 14:45