新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)程序-點(diǎn)陣LED顯示I LVOE U

單片機(jī)程序-點(diǎn)陣LED顯示I LVOE U

作者: 時(shí)間:2016-12-02 來(lái)源:網(wǎng)絡(luò) 收藏
本程序所用的原理圖下載:點(diǎn)這里,單片機(jī)芯片使用的stc89c52;找到點(diǎn)陣部分的原理圖即可.這是一整個(gè)單片機(jī)開(kāi)發(fā)板的電路圖其他的忽略

一下是程序源碼:
/******點(diǎn)陣LED顯示I LVOE U**************/
/**
*功能:點(diǎn)陣LED延時(shí)一秒顯示I 心形 U(I LOVE YOU)
*作者:徐冉
*日期:2013-06-12
*備注:程序順利調(diào)試成功
**/
/*************AT89C52-RC MCU*******************/
/**************51hei開(kāi)發(fā)板********************/
#include
typedef unsigned int uint;
typedef unsigned char uchar;
sbit din = P2^0;//數(shù)據(jù)輸入端
sbit cs = P2^1;//片選端
sbit clk = P2^2; //時(shí)鐘信號(hào)端
//字模取模編碼
uchar code dis[][8] = {
{0x00,0x3C,0x18,0x18,0x18,0x18,0x3C,0x00},// I
{0x00,0x6C,0xFE,0xFE,0x7C,0x38,0x10,0x00}, // 心形
{0x00,0xC3,0xC3,0xC3,0xC3,0xC3,0x7E,0x3C} // U
};
//delay:xms
void delay(uint xms)
{
uint x, y;
for(x = 0; x < xms; x++)
for(y = 0; y < 110; y++);
}
//寫MAX7219字節(jié)
void write_byte(uchar dat)
{
uchar i = 0;
cs = 0;
for(i = 0; i < 8; i++)
{
clk = 0;
din = (dat & 0x80);
dat <<= 1;
clk = 1;
}
}
//寫入MAX7219數(shù)據(jù)
void write_max7219(uchar address, uchar date)
{
cs = 0;
write_byte(address);//寫地址
write_byte(date); //寫入數(shù)據(jù)
cs = 1;
}
//MAX7219初始化
void max7219_init()
{
write_max7219(0x0c, 0x01);
write_max7219(0x09, 0x00);
write_max7219(0x0a, 0x04);
write_max7219(0x0b, 0x07);
write_max7219(0x0f, 0x00);
}
//主程序
void main(void)
{
uchar i, j;
max7219_init();
while(1)
{
for(j = 0; j < 3; j++)
{
for(i = 0; i < 8; i++)
{
write_max7219(i+1, dis[j][i]);
delay(1);
}
delay(1000);
}
}
}

本文引用地址:http://m.butianyuan.cn/article/201612/324601.htm


評(píng)論


技術(shù)專區(qū)

關(guān)閉