心血来潮,想捡一下丢了很久的单片机,纪录一下单片机学习简单的点阵显示,及踩到的䟘,找到吃灰很久的普中科技开发板(非广告,为毕设学习买的)。
使用开发板:
普中科技开发板
编译软件:
keil
点阵线路图: POW 为 74HC595 芯片 输出。
使用74HC595 扩展线路,74HC595 用作把 串行信号 转换 并行信号 。还可以 节约 单片机(MCU)的 IO 口,用 3 个 IO 口 可以控制 8 个 引脚。
74HC595由 两个寄存器 组成:移位寄存器和存储/输出寄存器,
两者都有8位宽度。移位寄存器负责在时钟脉冲的上升沿接收输入数据,而存储寄存器负责将数据传送到 输出引脚( q0->q7)
输出使能输入(~ OE)) 该引脚 用于 启用或禁用( Q0-Q7)。 低电平有效。
#include "reg51.h"
#include
typedef unsigned int u16;
typedef unsigned char u8;
sbit RCLK = P3^5;
sbit SRCLK = P3^6;
sbit SET = P3^4;
void delay(u16 i)
{
while(i--);
}
/*******************************************************************************
* 函 数 名 : spaceLatticeSend
* 函数功能 : 通过74HC595 串行口将数据 并行 输出
* 注意事项:。
*******************************************************************************/
void spaceLatticeSend(u8 dat)
{
u8 i;
RCLK = 0;
SRCLK = 0;
//1001 1101
for(i =0; i < 8;i++)
{
SET = dat>>7;//SET = 1;
SRCLK =1;
dat <<=1; // dat = 0011 1010
_nop_();
_nop_();
SRCLK = 0;
}
RCLK = 1;
_nop_();
_nop_();
RCLK=0;
}
/*******************************************************************************
* 函 数 名 : displayOneDot
* 函数功能 : 8*8 点阵 显示 控制一个点
*******************************************************************************/
void displayOneDot()
{
//u8 a = 0xff;//0x80
//u8 b=0x7f;//0x7f
u8 a = 0x04;//0x80
u8 b=0xEf;//0x7f
spaceLatticeSend(a);
P0=b;
while(1);
}
/*******************************************************************************
* 函 数 名 : displayNumber
* 函数功能 : 8*8 点阵 显示 数字或汉字
*******************************************************************************/
void displayNumber()
{
//u8 a[] = {0xff, 0x81,0x81,0x81,0x81,0x81,0x81,0xff};
//u8 b[] = {0x7f, 0xbf,0xcf,0xef,0xf7,0xfb,0xfd,0xfe};
//u8 a[]={0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00};
//u8 b[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//1
//u8 a[] = {0x00,0x00,0x60,0xFF,0xFF,0x00,0x00,0x00};
//u8 b[] = {0x7f, 0xff,0xdf,0xef,0xf7,0xff,0xff,0xff};
//2
//u8 a[] = {0x00,0x63,0x85,0x89,0x91,0x61,0x03,0x00};
//u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xff};
//3
//u8 a[] = {0x00,0x42,0x81,0x89,0x89,0x95,0xE3,0x00};
//u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xff};
//4
//u8 a[] = {0x00,0x0C,0x14,0x25,0x45,0xFF,0x05,0x05};
//u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//5
//u8 a[] = {0x00,0xE6,0xA1,0xA1,0xA1,0x92,0x0C,0x00};
//u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xff};
//5
//u8 a[] = {0x00,0xE6,0xA1,0xA1,0xA1,0x92,0x0C,0x00};
//u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xff};
//6
//u8 a[] = {0x00,0x3C,0x4A,0x91,0x91,0x52,0x0C,0x00};
//u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xff};
//7
//u8 a[] = {0x00,0xC0,0x80,0x80,0x8F,0x90,0xA0,0xC0};
//u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//8
//u8 a[] = {0x00,0x62,0x95,0x89,0x89,0x95,0x62,0x00};
//u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//9
//u8 a[] = {0x32,0x49,0x89,0x89,0x89,0x52,0x3C,0x00};
//u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
//中
u8 a[] = {0x3C,0x28,0x28,0xFF,0x28,0x28,0x3C,0x00};
u8 b[] = {0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xff};
while(1)
{
u8 i;
P0 = 0xFF;
for(i=0; i < 8; i++)
{ P0 = b[i];
spaceLatticeSend(a[i]);
delay(100);
spaceLatticeSend(0x00);
}
}
}
void main()
{
//displayOneDot();
displayNumber();
}