#include <REG51.H>
#include <intrins.h>
#include "array.h"
//--重定义函数变量--//
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
//--定义SPI要使用的 IO--//
sbit MOSIO = P3^4;
sbit R_CLK = P3^5;
sbit S_CLK = P3^6;
//--全局函数声明--//
void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0);
/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main(void)
{
int k, j, ms;
//--定义一个指针数组指向每个汉字--//
uchar *p[] ={tab17, tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8,
tab9, tab10, tab11, tab12, tab13, tab14, tab15, tab16};
while(1)
{
for(ms = 20; ms > 0; ms--) //移动定格时间设置
{
for(k = 0; k < 16; k++) //显示一个字
{
HC595SendData(~(*(p[0] + 2*(k+j) + 1)),~(*(p[0] + 2*(k+j) )),tab0[2*k],tab0[2*k + 1]); //因为字模软件取的数组是高电平有效,所以列要取反
}
//--清屏--//
HC595SendData(0xff,0xff,0,0); //清屏
}
j++;
if(j == (17*15) )
{
j = 0;
}
}
}
/*******************************************************************************
* 函 数 名 : HC595SendData
* 函数功能 : 通过595发送四个字节的数据
* 输 入 : BT3:第四个595输出数值
* * BT2: 第三个595输出数值
* * BT1:第二个595输出数值
* * BT0:第一个595输出数值
* 输 出 : 无
*******************************************************************************/
void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0)
{
uchar i;
//--发送第一个字节--//
for(i=0;i<8;i++)
{
MOSIO = BT3 >> 7 ; //从高位到低位
BT3 <<= 1;
S_CLK = 0;
S_CLK = 1;
}
//--发送第一个字节--//
for(i=0;i<8;i++)
{
MOSIO = BT2 >>7; //从高位到低位
BT2 <<= 1;
S_CLK = 0;
S_CLK = 1;
}
//--发送第一个字节--//
for(i=0;i<8;i++)
{
MOSIO = BT1 >> 7; //从高位到低位
BT1 <<= 1;
S_CLK = 0;
S_CLK = 1;
}
//--发送第一个字节--//
for(i=0;i<8;i++)
{
MOSIO = BT0 >> 7; //从高位到低位
BT0 <<= 1;
S_CLK = 0;
S_CLK = 1;
}
//--输出--//
R_CLK = 0; //set dataline low
R_CLK = 1; //片选
R_CLK = 0; //set dataline low
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#include <reg52.h>
#define uchar unsigned char
uchar i,j,k=15;
sbit xsi=P2^0;
sbit xrck=P2^1;
sbit xsck=P2^2;
sbit ysi=P2^3;
sbit yrck=P2^4;
sbit ysck=P2^5;
sbit kg= P3^2;
uchar code zbm[][32]={
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,},
{0xFF,0xFF,0xFF,0xF7,0xBF,0xF7,0xBF,0xFB,0xBF,0xFD,0x03,0xE0,0xFF,0xFF,0xFF,0xFF,
0x01,0xF0,0x7F,0xEF,0xBF,0xEF,0x9F,0xEF,0xDF,0xEF,0xFF,0xF1,0xFF,0xFF,0xFF,0xFF},/*"北",0*/
{0xF7,0xFF,0xF7,0xFF,0xF7,0xEF,0xF7,0xF3,0x37,0xFF,0xB7,0xFE,0xB6,0xDE,0xD5,0x80,
0xDB,0xFE,0x5B,0xFF,0x9B,0xFB,0xFB,0xF7,0xFB,0xE7,0xFB,0xFF,0xFF,0xFF,0xFF,0xFF},/*"京",1*/
{0xFF,0xEF,0x5F,0xF7,0xDF,0xFA,0xEF,0xFD,0x0F,0xFA,0xFF,0xDF,0xBF,0xEF,0xC7,0xF3,
0x58,0xFC,0xEF,0xFB,0xAF,0xF7,0xCF,0xEF,0xEF,0xCF,0xFF,0xDF,0xFF,0xDF,0xFF,0xFF},/*"欢",2*/
{0xBF,0xF7,0xBF,0xF7,0xBB,0xF6,0x37,0xF1,0xFF,0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,0xFB,0x37,0xFB,0x57,0xFB},
{0x67,0xFB,0x19,0x80,0xBB,0xFD,0xBB,0xFD,0xBF,0xFD,0xFF,0xFD,0xFF,0xFD,0xFF,0xFF},/*"阵",4*/
{0xFF,0xEF,0xFF,0xF7,0xFF,0xF9,0x7F,0xFE,0x81,0xBD,0x75,0xDD,0x65,0xE5,0x55,0xF8},
{0xB6,0xFD,0x9A,0xFD,0x28,0x80,0xBC,0xFE,0xBF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFF},/*"屏",5*/
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,},
};
void ys (uchar a) { //延时
uchar b;
for (;a>0;a--)
for (b=100;b>0;b--) ;
}
void yfs() {//Y轴发数
ysck=0;
yrck=0;
k++;
if (k==16) {
k=0;
ysi=0;
}
else
ysi=1;
ysck=1;
P2=P2|0X14;
//相当于 xrck=1; yrck=1;
}
void xfs(uchar a) { //X轴发数
uchar b,a1,a2;
a1=~zbm[6][a*2+1];
a2=~zbm[6][a*2];
xsck=0;
xrck=0;
for (b=0;b<8;b++) {
a1=a1<<1;
xsi=CY;
xsck=1;
xsck=0;
}
for (b=0;b<8;b++) {
a2=a2<<1;
xsi=CY;
xsck=1;
xsck=0;
}
}
void fs(uchar a) { //X轴发数
uchar b;
xsck=0;
xrck=0;
for (b=0;b<8;b++) {
a=a<<1;
xsi=CY;
xsck=1;
xsck=0;
}
}
void gdhs(uchar *zz,uchar N,uchar Time) //流动显示N个汉字 滚动函数
{ //参数三个:字符串字模首地址、字数、显示流动速度
uchar FontNum,i,j,row; //循环变量,字数计数、16次流动、16列扫描
for(FontNum=0;FontNum<N;FontNum++) {
for(i=0;i<16;i++) //字到字流动 16次左移才能完成
{
for(j=0;j<Time;j++) //显示延迟,决定流动速度
{
k=15;
for(row=0;row<16;row++) //显示16*16屏幕一次
{
yfs(); //选通显示列 //行选线,P3 低四位
fs (~*(zz+FontNum*32+(i+row)*2+1)); //以移动偏移为基础获取新数据
fs(~*(zz+FontNum*32+(i+row)*2)); //获取显示数据 循环显示关键算法
ys (12); //适当延时
}
}
}
}
}
void wbzd () interrupt 0 { //外部中断
j++;
if (j>1)
j=0;
ys(10);
while (!kg) {
k=15;
for (i=0;i<16;i++) {
yfs();
xfs(i);
ys(10);
}
}
if (j==0)
gdhs(zbm,8,2);
if (j==1)
gdhs(zbm1,10,1);
}
void main () {
EA = 1; //打开总中断
EX0=1;
IT0=1;
while (1) {
if (j==0)
gdhs(zbm,8,5);
if (j==1)
gdhs(zbm1,10,3);
}
}
一周热门 更多>