標(biāo)題:
點(diǎn)陣顯示 I LOVE YOU
[打印本頁]
作者:
daming
時(shí)間:
2014-12-29 19:36
標(biāo)題:
點(diǎn)陣顯示 I LOVE YOU
/*作用:顯示 I love you*/
#include<reg52.h> //頭文件
#define uchar unsigned char //宏定義
#define uint unsigned int
uchar code table[]= // 定義數(shù)組常量,該常量用于數(shù)碼管顯示
{0x30,0x38,0x3f,0x3e,0x79,//l love you,前面加code該常量在程序
0x6e,0x3f,0x3e}; //代碼中存放,不占用RAM
void delay(uint x) //延時(shí)子函數(shù),時(shí)間約為0.002xS
{
uint i,j;
for(i=x;i>0;i--)
for(j=200;j>0;j--);
}
void display(uchar *lp,uchar lc) //顯示子函數(shù)
{
uchar i; //定義局部變量
while(1)
{
P1=0xf8; //點(diǎn)亮第一個(gè)數(shù)碼管
P2=0;
for(i=0;i<lc;i++)
{
P2=lp[i];
delay(1);
P2=0; //消隱
P1++;
}
}
}
void main() //主函數(shù)
{
while(1)
{
display(table,8); //條用子函數(shù)顯示 l love you
}
}
/*注:
數(shù)碼管與P2口相連,低電平有效
*/
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1