|
/***************************************************************************
* 文件名:SEG 012345.c
* 功 能:六位數(shù)碼管從左到右顯示543210六位數(shù)字
* 作 者:
* 日 期:
* 備 注:
//軟件思路:利用人眼睛的視覺(jué)暫留,迅速依次點(diǎn)亮數(shù)碼管,
// 使人們以為幾個(gè)數(shù)碼管是全亮的
//開(kāi)發(fā)板連接方法:把JP2跳線帽接上,JP3 SEG1 SEE2接上,JP1 跳線帽取下
****************************************************************************/
#include<pic.h> //包含單片機(jī)內(nèi)部資源預(yù)定義
__CONFIG(0x1832);
//芯片配置字,看門狗關(guān),上電延時(shí)開(kāi),掉電檢測(cè)關(guān),低壓編程關(guān),加密,4M晶體HS振蕩
void delay(); //delay函數(shù)申明
//定義常數(shù)0-9的數(shù)據(jù)表格
const unsigned char TABLE[] = {0x3f,0x6,0x5b,0x4f,0x66,0x6d,0x7c,0x7,0x7f,0x6f};
/****************************************************************************
* 名 稱:main()
* 功 能:主函數(shù)
* 入口參數(shù):
* 出口參數(shù):
* 說(shuō) 明:
****************************************************************************/
void main()
{
TRISD = 0; //portd 輸出
TRISA = 0; //porta 輸出
PORTA = 0x00; //禁止顯示
PORTD = 0x0f;
while (1) //死循環(huán),讓數(shù)碼管持續(xù)點(diǎn)亮
{
PORTD = TABLE[0]; //取出數(shù)據(jù),送D口顯示
PORTA = 0x01; //點(diǎn)亮第一個(gè)位數(shù)碼管
delay(); //延長(zhǎng)一段時(shí)間,保證亮度
PORTD = TABLE[1]; //顯示數(shù)據(jù)1(同數(shù)據(jù)0)
PORTA = 0x02;
delay();
PORTD = TABLE[2];
PORTA =0x04;
delay();
PORTD = TABLE[3];
PORTA = 0x08;
delay();
PORTD = TABLE[4];
PORTA = 0x10;
delay();
PORTD = TABLE[5];
PORTA = 0x20;
delay();
}
}
/****************************************************************************
* 名 稱:delay()
* 功 能:延時(shí)
* 入口參數(shù):
* 出口參數(shù):
* 說(shuō) 明:
****************************************************************************/
void delay()
{
int i; //定義整形變量
for (i = 60;i--;); //延時(shí)
}
|
|