//头文件111
#include
#include "intrins.h"
void Delay1ms();
void DelayNms(unsigned int t);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void main()
{
unsigned char i;
while(1)
{
P1 = 0xfe;//11111110
DelayNms(600);
// 第1种方法
for(i = 0;i < 4;i++)
{
P1 = _crol_(P1,2);
if(P1 != 0xfe)
DelayNms(600);
}
// 第2种方法
// for(i = 0;i < 4;i++)
// {
// P1 = LED_Table[i*2];
// if(P1 != 0xfe)
// DelayNms(600);
// }
}
}
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}
//头文件2222
#include
#include "intrins.h"
unsigned int count = 1994;
void Delay1ms();
void DelayNms(unsigned int t);
//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极
unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极
void int0_init()
{
EA = 1;
IT0 = 1;
EX0 = 1;
}
void int0_serve() interrupt 0
{
count++;
if(count >= 2000)
{
count = 0;
}
}
void main()
{
int0_init();
while(1)
{
//按键计数
P2 = SEG_Table[count/1000];
P1 = 0x01;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[(count%1000)/100];
P1 = 0x02;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[(count%100)/10];
P1 = 0x04;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[count%10];
P1 = 0x08;
DelayNms(2);
P2 = 0xff;
//学号
P2 = SEG_Table[0];
P1 = 0x40;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[6];
P1 = 0x80;
DelayNms(2);
P2 = 0xff;
}
}
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}
//头文件3333
#include
#include "intrins.h"
unsigned int flag = 0;
unsigned char time_count = 0;
void Delay1ms();
void DelayNms(unsigned int t);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极
unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极
void Timer0_init()
{
TMOD |= 0X01;
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void Timer_0serve() interrupt 1
{
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
flag++;
if(flag == 20)
{
flag = 0;
time_count++;
if(time_count >= 16) // 学号为06
{
time_count = 16;
}
}
}
void main()
{
Timer0_init();
while(1)
{
P2 = SEG_Table[time_count/10];
DelayNms(10);
P1 = 0x02;
P2 = 0xff;
P2 = SEG_Table[time_count%10];
DelayNms(10);
P1 = 0x01;
P2 = 0xff;
}
}
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}
//头文件4444
#include
#include "intrins.h"
sbit key = P3^3;
unsigned int count = 1000;
unsigned char i;
void Delay1ms();
void DelayNms(unsigned int t);
void SendChar(unsigned char dat);
void SendString(unsigned char *s);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极
unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极
void count0_serve(void) interrupt 3
{
count++;
if(count >= 100)
{
count = 0;
}
}
void seg_disp(unsigned int value)
{
P2 = SEG_Table[value/10];
DelayNms(200);
P1 = 0x02;
P2 = 0xff;
P2 = SEG_Table[value%10];
DelayNms(200);
P1 = 0x01;
P2 = 0xff;
}
void main()
{
TMOD = 0x20; //方式2
TH1 = TL1 =0xfd;//9600bit/s
EA = 1;
ET1 = 1;
TR1=1;
SCON =0x40;
TCON |=0x10;
SendString("Test String");
SendString("\r\n");
while(1)
{
SendString("InitValue is:94");
seg_disp(count);
}
}
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}
void SendChar(unsigned char dat)
{
SBUF = dat;
while(TI==0);//等待发送完成 TI=1
TI=0;
}
void SendString(unsigned char *s)
{
while(*s!='\0')
{
SendChar(*s);
s++;
}
}
//头文件111
#include
#include "intrins.h"
void Delay1ms();
void DelayNms(unsigned int t);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void main()
{
unsigned char i;
while(1)
{
P1 = 0xfe;//11111110
DelayNms(600);
// 第1种方法
for(i = 0;i < 4;i++)
{
P1 = _crol_(P1,2);
if(P1 != 0xfe)
DelayNms(600);
}
// 第2种方法
// for(i = 0;i < 4;i++)
// {
// P1 = LED_Table[i*2];
// if(P1 != 0xfe)
// DelayNms(600);
// }
}
}
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}
//头文件2222
#include
#include "intrins.h"
unsigned int count = 1994;
void Delay1ms();
void DelayNms(unsigned int t);
//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极
unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极
void int0_init()
{
EA = 1;
IT0 = 1;
EX0 = 1;
}
void int0_serve() interrupt 0
{
count++;
if(count >= 2000)
{
count = 0;
}
}
void main()
{
int0_init();
while(1)
{
//按键计数
P2 = SEG_Table[count/1000];
P1 = 0x01;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[(count%1000)/100];
P1 = 0x02;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[(count%100)/10];
P1 = 0x04;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[count%10];
P1 = 0x08;
DelayNms(2);
P2 = 0xff;
//学号
P2 = SEG_Table[0];
P1 = 0x40;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[6];
P1 = 0x80;
DelayNms(2);
P2 = 0xff;
}
}
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}
//头文件3333
#include
#include "intrins.h"
unsigned int flag = 0;
unsigned char time_count = 0;
void Delay1ms();
void DelayNms(unsigned int t);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极
unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极
void Timer0_init()
{
TMOD |= 0X01;
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void Timer_0serve() interrupt 1
{
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
flag++;
if(flag == 20)
{
flag = 0;
time_count++;
if(time_count >= 16) // 学号为06
{
time_count = 16;
}
}
}
void main()
{
Timer0_init();
while(1)
{
P2 = SEG_Table[time_count/10];
DelayNms(10);
P1 = 0x02;
P2 = 0xff;
P2 = SEG_Table[time_count%10];
DelayNms(10);
P1 = 0x01;
P2 = 0xff;
}
}
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}
//头文件4444
#include
#include "intrins.h"
sbit key = P3^3;
unsigned int count = 1000;
unsigned char i;
void Delay1ms();
void DelayNms(unsigned int t);
void SendChar(unsigned char dat);
void SendString(unsigned char *s);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极
unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极
void count0_serve(void) interrupt 3
{
count++;
if(count >= 100)
{
count = 0;
}
}
void seg_disp(unsigned int value)
{
P2 = SEG_Table[value/10];
DelayNms(200);
P1 = 0x02;
P2 = 0xff;
P2 = SEG_Table[value%10];
DelayNms(200);
P1 = 0x01;
P2 = 0xff;
}
void main()
{
TMOD = 0x20; //方式2
TH1 = TL1 =0xfd;//9600bit/s
EA = 1;
ET1 = 1;
TR1=1;
SCON =0x40;
TCON |=0x10;
SendString("Test String");
SendString("\r\n");
while(1)
{
SendString("InitValue is:94");
seg_disp(count);
}
}
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}
void SendChar(unsigned char dat)
{
SBUF = dat;
while(TI==0);//等待发送完成 TI=1
TI=0;
}
void SendString(unsigned char *s)
{
while(*s!='\0')
{
SendChar(*s);
s++;
}
}