目錄
74HC595簡介(個人理解)與模塊代碼
軟件仿真和代碼?
74HC595簡介(個人理解)與模塊代碼
SHCP是寫入595芯片數(shù)據(jù)的配置
STCP是發(fā)送595芯片內(nèi)信息的配置
DS是數(shù)據(jù)配置的區(qū)域
595芯片有9個輸出引腳,最后一個是供給下一塊串聯(lián)的595使用的,下一塊串聯(lián)的595stcp和shcp與上一塊連接的引腳一致,下一塊的DS與上一塊的第9個引腳相連。
實現(xiàn)了3位引腳當(dāng)8位使用的功能,節(jié)省引腳。
595串聯(lián)的數(shù)據(jù)流動規(guī)則:倘若堆了16位數(shù)據(jù)進(jìn)來,前八位會被推送到第二塊串聯(lián)的595芯片之中,后八位放在第一塊595芯片內(nèi)
通用配置:
定義引腳
sbit DS=P2^1;
sbit shcp=P2^0;
sbit stcp=P2^2;
寫數(shù)值
unsigned char i;
for(i=0; i<8; i++)
{
DS = Data_row & (0x80 >> i); // 從高到低遍歷寫入數(shù)據(jù)
shcp = 0;
_nop_(); // 軟件仿真處理速度較慢,故做此延遲
_nop_();
shcp = 1;
}
發(fā)送數(shù)值
stcp = 0;
_nop_();
_nop_();
stcp = 1;
軟件仿真和代碼?
用的pctolcd2002生成字模,這個可以設(shè)置的東西有很多,相較于其他的軟件,這個更好用。
本次實驗中使用的字模顯示邏輯是
紅色代表第一次刷新的字模;橙色代表第二次刷新的字模;藍(lán)色代表第三次刷新的字模;綠色代表第四次刷新的字模。
顯示流動刷新邏輯——一個簡單的定時器輸出給燈亮的那部分代碼即可
文章來源:http://www.zghlxwxcb.cn/news/detail-742462.html
主函數(shù)部分
#include <reg51.h>
#include <intrins.h>
#include "Delay.h"
#include "timer0.h"
#include "matrixled.h"
// 定義常量
#define TOTAL_ROWS 16
#define SHIFT_INTERVAL 100 // 定義0.1s的間隔為100
// 定義變量
unsigned char offset = 0; // 顯示上升變量
// “我是龜甲”字模數(shù)組
unsigned code MatrixLed_Code[128] = {
0x04, 0x40, 0x0E, 0x50, 0x78, 0x48, 0x08, 0x48, 0x08, 0x40,
0xFF, 0xFE, 0x08, 0x40, 0x08, 0x44, 0x0A, 0x44, 0x0C, 0x48,
0x18, 0x30, 0x68, 0x22, 0x08, 0x52, 0x08, 0x8A, 0x2B, 0x06,
0x10, 0x02, 0x1F, 0xF0, 0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0xF0, 0x00, 0x00, 0xFF, 0xFE,
0x01, 0x00, 0x11, 0x00, 0x11, 0xF8, 0x11, 0x00, 0x29, 0x00,
0x45, 0x00, 0x83, 0xFE, 0x04, 0x00, 0x04, 0x00, 0x0F, 0xE0,
0x10, 0x20, 0x20, 0x40, 0x7F, 0xF8, 0xA1, 0x08, 0x21, 0x08,
0x3F, 0xF8, 0x21, 0x08, 0x21, 0x08, 0x3F, 0xF8, 0x21, 0x08,
0x01, 0x02, 0x01, 0x02, 0x00, 0xFE, 0x00, 0x00, 0x3F, 0xF8,
0x21, 0x08, 0x21, 0x08, 0x21, 0x08, 0x3F, 0xF8, 0x21, 0x08,
0x21, 0x08, 0x21, 0x08, 0x3F, 0xF8, 0x21, 0x08, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00
};
// 掃描矩陣LED
void main(void)
{
Timer0_Init(); // 定時器初始化
while(1)
{
static unsigned char i = 0;
// 輸入兩組八位的行選數(shù)據(jù),選擇十六行的其中一行點亮
if(i < 8)
{
HC595_write_row(0x00);
HC595_write_row(0x01 << i);
HC595_Latch_row();
}
else // i >= 8
{
HC595_write_row(0x01 << i - 8);
HC595_write_row(0x00);
HC595_Latch_row();
}
// 列選燈亮,輸入兩組數(shù)據(jù),左半邊一個,右半邊一個
HC595_write_column(~MatrixLed_Code[2 * (i + offset) + 1]);
HC595_Latch_column();
HC595_write_column(~MatrixLed_Code[2 * (i + offset)]);
HC595_Latch_column();
Delay(1);
// 消影操作,但效果很奇怪,故注釋掉了
// HC595_write_row(0x00);
// HC595_write_row(0x00);
// HC595_Latch_row();
i++;
if(i == TOTAL_ROWS)
i = 0;
}
}
// 定時器0中斷服務(wù)函數(shù)
void Timer0_Routine() interrupt 1
{
static unsigned char count = 0;
TL0 = 0x66; // 設(shè)置定時初始值,1ms
TH0 = 0xFC;
count++;
// 每隔0.1s,顯示就往下移一行
if(count == SHIFT_INTERVAL)
{
count = 0;
offset++;
if(offset == 64)
offset = 0;
}
}
74HC595控制點陣屏顯示模塊
#include<reg51.h>
#include<intrins.h>
#include "Delay.h"
// 定義引腳
sbit DS=P2^1; // 普通的是行選的74HC595
sbit shcp=P2^0;
sbit stcp=P2^2;
sbit DS1=P2^4; // 帶數(shù)字1的是行選燈亮的74HC595
sbit shcp1=P2^3;
sbit stcp1=P2^5;
// 向595芯片寫行數(shù)據(jù)
void HC595_write_row(unsigned char Data_row)
{
unsigned char i;
for(i=0; i<8; i++)
{
DS = Data_row & (0x80 >> i); // 從高到低遍歷寫入八位行選數(shù)據(jù)
shcp = 0;
_nop_(); // 軟件仿真處理速度較慢,故做此延遲
_nop_();
shcp = 1;
}
}
// 向595芯片寫列數(shù)據(jù)
void HC595_write_column(unsigned char Data_column)
{
unsigned char i;
for(i=0; i<8; i++)
{
DS1 = Data_column & (0x80 >> i); // 從高到低遍歷寫入八位行選燈亮的(列)數(shù)據(jù)
shcp1 = 0;
_nop_();
_nop_();
shcp1 = 1;
}
}
// 觸發(fā)595的行鎖存
void HC595_Latch_row(void)
{
stcp = 0;
_nop_();
_nop_();
stcp = 1;
}
// 觸發(fā)595的列鎖存
void HC595_Latch_column(void)
{
stcp1 = 0;
_nop_();
_nop_();
stcp1 = 1;
}
定時器模塊
#include <REGX52.H>
/**
* @brief 定時器0初始化,1毫秒@11.0592MHz
* @param 無
* @retval無
*/
void Timer0_Init()//創(chuàng)建精確的時間延時或進(jìn)行時間相關(guān)的任務(wù)
{
TMOD &= 0xF0; //設(shè)置定時器模式
TMOD |= 0x01; //設(shè)置定時器模式
TL0 = 0x66; //設(shè)置定時初始值
TH0 = 0xFC; //設(shè)置定時初始值
TF0 = 0; //清除TF0標(biāo)志
TR0 = 1; //定時器0開始計時
ET0=1;//允許中斷
EA=1;//允許總中斷
PT0=0;//配置優(yōu)先級
}
Delay延時模塊
#include <intrins.h>
void Delay(unsigned int xms)
{
unsigned char data i, j;
while(xms--)
{
_nop_();
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
}
軟件仿真文章來源地址http://www.zghlxwxcb.cn/news/detail-742462.html
到了這里,關(guān)于使用74HC595完成16*16led矩陣廣告牌(51單片機(jī)軟件仿真)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!