|
//------------2_8數(shù)碼管鍵調(diào)時帶小數(shù)點功能
#include<iom128v.h>
#define uchar unsigned char
#define uint unsigned int
#define P0_1 PORTA |= (1<<0)
#define P0_0 PORTA &=~ (1<<0)
#define P1_1 PORTA |= (1<<1)
#define P1_0 PORTA &=~ (1<<1)
#define P2_1 PORTA |= (1<<2)
#define P2_0 PORTA &=~ (1<<2)
#define P3_1 PORTA |= (1<<3)
#define P3_0 PORTA &=~ (1<<3)
#define P4_1 PORTA |= (1<<4)
#define P4_0 PORTA &=~ (1<<4)
#define P5_1 PORTA |= (1<<5)
#define P5_0 PORTA &=~ (1<<5)
#define P6_1 PORTA |= (1<<6)
#define P6_0 PORTA &=~ (1<<6)
#define P7_1 PORTA |= (1<<7)
#define P7_0 PORTA &=~ (1<<7)
uchar i,m,h;
uint j;
uchar led_discode[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,0xbf,0xef,}; //共陽數(shù)碼管數(shù)字碼
void delay(uint mS) //微秒
{
{
uchar x,y;
for(x=0;x<mS;x++)
for(y=0;y<10;y++);
}
}
void init(void) //初始化PORUT口
{
DDRA=0XFF; //LED IO口設(shè)為輸出
PORTA=0X00;
DDRB |=0X10; //PB4設(shè)為輸出
PORTB|=0X10; //關(guān)閉PB4外接的LED
DDRC=0XFF; //數(shù)碼管段選設(shè)為輸出
PORTC=0X00;
DDRF |=0X03; //LED及數(shù)碼管鎖存IO口設(shè)為輸出
PORTF|=0X0E;
PORTF&=0xF7; //鎖存數(shù)據(jù)關(guān)閉數(shù)碼管
DDRD=0;//全部設(shè)為輸入
PORTD=0xff;//全部上拉
PIND=0xff;//設(shè)初始值
}
void playh(uchar h)
{
PORTC = led_discode[h/10] ;
P0_1;
delay(1);
P0_0;
PORTC =tablee[h%10];
P1_1;
delay(1);
P1_0;
PORTC = led_discode[10] ;
P2_1;
delay(1);
P2_0;
}
void key1(void)
{
if(PIND == 0xfe) //按鍵掃描函數(shù)----------加鍵
{
delay(5);
if(PIND == 0xfe)
{
while(PIND == 0xfe);
m++;
}
}
}
void key2(void)
{
if(PIND == 0xfd) //按鍵掃描函數(shù)----------減鍵
{
delay(5);
if(PIND == 0xfd)
{
while(PIND == 0xfd) play(i);
h++;
}
}
}
void main (viod)
{
init() ;
while(1)
{
key1();
key2();
j=300;
while(j--)
{
play(i); //顯示函數(shù)
}
i++;
if(i==60)
{
i=0; //如果秒計滿60,將秒計數(shù)變量清0
m++; //分鐘計數(shù)變量加1
}
if(m == 60)
{
m=0; //如果分鐘計滿60,將分鐘計數(shù)變量清0
h++; //小時計數(shù)變量加1
}
if(h == 24)
{
h=0; //如果小時計滿24,將小時計數(shù)變量清0
}
}
}
完全代碼與仿真文件附件中
帶點數(shù)碼管.zip
(25.14 KB, 下載次數(shù): 15)
2018-12-15 14:33 上傳
點擊文件名下載附件
|
評分
-
查看全部評分
|