#include <reg52.h>
#include "LCD1602.h"
uint Num=0;
uchar NumCode[4]={0,0,0,0};
//---------------中断加一--------------
void my_INT1(void) interrupt 0
{
Num++;
}
//-----------------------------
void Disp()
{
uint m;
NumCode[0]=Num/1000;
NumCode[1]=Num%1000/100;
NumCode[2]=Num%100/10;
NumCode[3]=Num%10;
for(m=0;m<4;m++)
{
LCD_Disp(0,5+m,NumCode[m]+0x30);
}
}
//---------------------
void main()
{
IT0=1;EA=1;EX0=1;
LCD_Init();
while(1)
{
Disp();
}
}
#include <reg52.h>
#include "LCD1602.h"
uint Num=3728;
uchar NumCode[4]={0,0,0,0};
//-----------------------自动加一-------------------------
void Disp()
{
uchar m;
NumCode[0]=Num/1000;
NumCode[1]=Num%1000/100;
NumCode[2]=Num%100/10;
NumCode[3]=Num%10;
for(m=0;m<4;m++)
{
LCD_Disp(0,6+m,NumCode[m]+0x30);
}
}
//--------------------------------------------
void main()
{
LCD_Init();
while(1)
{
Disp();
Num++;
Delay(50000);
}
}
#include<reg51.h>
#include "LCD1602.h"
uint Num=5432;
uchar NumCode[4]={0,0,0,0};
//----------定时器T0按键加一---------------
void T0Init()
{ TMOD=0x0d;
TH0=5432/256;
TL0=5432%256;
TR0=1; }
//------------------------------------------
void Disp()
{ int m;
NumCode[0]=Num/1000;
NumCode[1]=Num%1000/100;
NumCode[2]=Num%100/10;
NumCode[3]=Num%10;
for(m=0;m<4;m++)
{
LCD_Disp(0,5+m,NumCode[m]+0x30);
}
}
//-------------------------------------------
void main()
{
T0Init();
LCD_Init();
while(1)
{
Num=TH0*256+TL0;
Disp();
}
}
#include<reg51.h>
#define uchar unsigned char
uchar T0Num;
sbit LED=P1^0;
//--------定时器TO使LED自动一秒闪一下---------
void T0Init()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TR0=1;
ET0=1;
EA=1;
}
//---------------------------
void T0Sever() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
T0Num++;
if(T0Num==100)
{
LED=~LED;
T0Num=0;
}
}
//---------------------------
void main()
{
T0Init();
while(1)
{
}
}
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num[10]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
uint shu;
//-----------外部中断按键加减一----------
void my_INT1(void) interrupt 0
{
shu--;
}
//-----------------------------------------------------
void my_INT2(void) interrupt 2
{
shu++;
}
//------------------------------------------------------
void main()
{
shu=5;
IT0=1;EA=1;EX0=1;
IT1=1;EA=1;EX1=1;
while(1)
{
P2=num[shu];
if(shu==10){shu=0;}
if(shu==-1){shu=9;}
}
}
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar Disp[4]={0x9a,0xca,0xa9,0xac};
//------------------------交通灯---------------------
void delay3ms(uchar i)
{
uint n,j,k;
for(;i>=1;i--)
{
for(n=2;n>=1;n--)
{
for(j=250;j>=1;j--)
{
for(k=200;k>=1;k--);
}
}
}
}
//-------------------------------------
void main()
{
while(1)
{
P1=Disp[0];delay3ms(4);
P1=Disp[1];delay3ms(1);
P1=Disp[2];delay3ms(4);
P1=Disp[3];delay3ms(1);
}
}
#include <reg51.h>
#define uchar unsigned char
uchar T0Num=0;
uchar PWM=50;
sbit LED=P3^7;
//------------PWM频率------
void T0Init()
{
TMOD=0x01;
TH0=(65536-100)/256;// 0.1ms
TL0=(65536-100)%256;
ET0=1;
EA=1;
TR0=1;
}
//-----------------------
void Ex0Init()
{
IT0=1;
EX0=1;
EA=1;
}
//------------------------
单片机编程100例详解void main()
{
T0Init();
Ex0Init();
while(1)
{
}
}
//------------------------
void T0Server() interrupt 1
{
TH0=(65536-100)/256;// 0.1ms
TL0=(65536-100)%256;
T0Num++;
if(T0Num==PWM)
{
LED=1;
}
if(T0Num==100)
{
T0Num=0;
LED=0;
}
}
//--------------------------
void Int0Server() interrupt 0
{
PWM=PWM+5;
if(PWM>=100)
{
PWM=0;
}
}
include<reg52.h>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论