单片机新手,麻烦大神看一眼,帮我解答一下
时间:10-02
整理:3721RD
点击:
这是第一个16*16点阵
#include <REG51.H>
#include <intrins.h>
#define NOP() _nop_() // 定义空指令 ,这个函数在库 <intrins.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;
//---全局变量声明--//
ulong column; //点阵列
ulong row; //点阵行
ulong dt;
//点阵显示数组
uchar code tab0[] = {0x00, 0x01,x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x80,
0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x80, 0x00};
//--亲--//
uchar code tab1[] = {
64,0,128,8,254,31,16,2,32,1,255,63,64,0,64,0,
254,31,64,0,72,6,68,8,82,16,32,0,0,0,0,0};
//--爱--//
uchar code tab2[] = {
0,14,252,1,72,8,144,4,254,63,2,16,33,8,252,
31,32,0,224,7,80,2,136,1,68,2,58,28,0,0,0,0};
//--的--//
uchar code tab3[] = {
8,2,8,2,4,17,62,63,162,16,98,16,34,17,62,
18,34,18,34,16,34,16,34,16,62,10,34,4,0,0,0,0};
//--顾--//
uchar code tab4[] = {
0,16,190,63,2,2,186,31,170,16,170,20,170,20,186,20,
138,20,138,20,170,20,26,10,1,49,193,32,0,0,0,0};
//--客--//
uchar code tab5[] = {
64,0,128,0,254,31,34,16,241,11,40,2,68,1,192,1,32,
2,248,63,23,4,16,4,16,4,240,7,0,0,0,0};
//--欢--//
uchar code tab6[] = {
0,1,0,1,63,1,32,63,162,32,148,18,84,2,8,2,
8,2,20,5,36,5,162,8,65,16,32,32,0,0,0,0};
//--迎--//
uchar code tab7[] = {
2,1,196,16,36,62,32,18,32,18,39,18,36,18,164,18,
100,18,36,26,4,2,10,2,49,0,192,63,0,0,0,0};
//--使--//
uchar code tab8[] = {
16,2,16,18,232,63,8,2,204,31,74,18,73,18,200,31,
8,18,72,2,136,2,8,1,136,6,104,56,0,0,0,0};
//--用--//
uchar code tab9[] = {
0,8,252,31,132,8,132,8,252,15,132,8,132,8,132,8,
252,15,132,8,132,8,130,8,130,10,129,4,0,0,0,0};
//--开--//
uchar code tab10[] = {
0,8,254,31,16,2,16,2,16,2,16,18,255,63,16,2,
16,2,16,2,16,2,8,2,4,2,3,2,0,0,0,0};
//--发--//
uchar code tab11[] = {
32,2,36,4,36,4,34,16,254,63,32,0,224,15,80,8,
80,4,136,2,8,1,132,2,98,60,29,16,0,0,0,0};
//--板--//
uchar code tab12[] = {
4,8,4,30,196,1,95,0,196,15,68,8,78,9,86,9,
69,5,69,5,68,2,36,5,164,56,84,16,0,0,0,0};
//--∩_∩--//
uchar code tab13[] = {
0,0,0,0,60,240,102,156,67,130,0,0,0,0,0,0,
0,0,0,0,48,24,96,8,192,7,0,0,0,0,0,0};
//函数声明
void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0);
/*************主函数*****************************/
void main(void)
{
int k, i, ms;
i = 80; //显示时间
while(1)
{
//--显示"亲"--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab1[2*k +1],~tab1[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“爱”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab2[2*k +1],~tab2[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“的”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab3[2*k +1],~tab3[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“顾”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab4[2*k +1],~tab4[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“客”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab5[2*k +1],~tab5[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“欢”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++) //欢
{
HC595SendData(~tab6[2*k +1],~tab6[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“迎”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab7[2*k +1],~tab7[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“使”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab8[2*k +1],~tab8[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“用”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab9[2*k +1],~tab9[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“开”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab10[2*k +1],~tab10[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示“发”--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab11[2*k +1],~tab11[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示"板"--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab12[2*k +1],~tab12[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,0);
//--显示"∩_∩"--//
for(ms = i; ms > 0; ms--)
{
for(k = 0; k < 16; k++)
{
HC595SendData(~tab13[2*k +1],~tab13[2*k],tab0[2*k],tab0[2*k + 1]);
}
}
//--清屏--//
HC595SendData(0xff,0xff,0,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
}
这是第二个16*16点阵
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define out0 P0
#define out2 P2
#define out1 P1
void delay(uint j)
{
uchar i=250;
for(;j>0;j--)
{
while(--i);
i=100;
}
}
uchar code string[]=
{
//电
0x7F,0xFF,0x7F,0xFF,0x7F,0xFF,0x03,0xE0,0x7B,0xEF,0x7B,0xEF,0x03,0xE0,0x7B,0xEF,
0x7B,0xEF,0x7B,0xEF,0x03,0xE0,0x7B,0xEF,0x7F,0xBF,0x7F,0xBF,0xFF,0x00,0xFF,0xFF,
//子
0xFF,0xFF,0x03,0xF0,0xFF,0xFB,0xFF,0xFD,0xFF,0xFE,0x7F,0xFF,0x7F,0xFF,0x7F,0xDE,
0x00,0X80,0x7F,0xFF,0x7F,0xFF,0x7f,0xFF,0x7F,0xFF,0x7F,0xFF,0x5F,0xFF,0xBF,0xFF,
//技
0xF7,0xFB,0xF7,0xFB,0xF7,0xFB,0x40,0X80,0xF7,0xFB,0xD7,0xFB,0x67,0xC0,0x73,0xEF,
0xF4,0xEE,0xF7,0xF6,0xF7,0xF9,0xF7,0xF9,0xF7,0xf6,0x77,0X8F,0X95,0xDF,0xFB,0xFF,
//术
0x7F,0xFF,0x7F,0xFB,0x7F,0xF7,0x7F,0xFF,0x00,0x80,0x7F,0xFF,0x3F,0xFE,0x5F,0xFD,
0x5F,0xFB,0x6f,0xF7,0x77,0xE7,0x7B,0x8F,0x7C,0xDF,0x7F,0xFF,0x7F,0xFF,0xFF,0xFF,
};
void main()
{
uchar i,j,n;
while(1)
{
for(j=0;j<4;j++)
{
for(n=0;n<40;n++)
{
for(i=0;i<16;i++)
{
out1=i%16;
out0=string[i*2+j*32];
out2=string[i*2+1+j*32];
delay(4);
out0=0xff;
out2=0xff;
}
}
}
}
}
为什么第一个程序在51单片机可以运行,第二个程序不可以运行,应该怎么修改?
你的问题呢~
硬件不知道。 而且你第一个程序用了595驱动,第二个程序貌似你采用IO口直接驱动,都没有595的驱动,如果你硬件是没变变动的,那么肯定运行不了了。
硬件和软件联合起来调试了啊
代码这么长还叫新手,我叫新新手