嵌入式单片机设计吧 关注:23贴子:95
  • 1回复贴,共1

51单片机驱动点阵屏8*32显示时钟

只看楼主收藏回复


#include<reg52.h>
#include <intrins.h>
#include "stdio.h"
#define uchar unsigned char
#define uint unsigned int
#define LED_DATA P2
sbit SCK= P1^7;
sbit RCK= P1^6;
sbit SER= P1^5;
void delay_ms(uint time){
uint i,j;
for(i = 0; i < time; i++){
for(j = 0; j < 10; j++);
}
}
char code font7_8[10][7]={
0xFF,0xC3,0x99,0xBD,0xBD,0x99,0xC3,//0;"0",0
0xFF,0xFF,0xBD,0xBD,0x81,0xBF,0xBF,//0;"1",1
0xBF,0x93,0x9D,0xAD,0xB5,0x99,0xFF,//0;"2",2
0xDF,0xBB,0xAD,0xAD,0xA5,0xC9,0xFF,//0;"3",3
0xCF,0xD7,0xDB,0x9B,0x81,0xDF,0xDF,//0;"4",4
0xFF,0xCB,0xB5,0xB5,0xB5,0xB5,0xCF,//0;"5",5
0xFF,0xC7,0xAB,0xB5,0xB5,0xB1,0xCB,//0;"6",6
0xFF,0xFD,0x9D,0xED,0xF5,0xF9,0xFD,//0;"7",7
0xFF,0xCB,0xB5,0xB5,0xA5,0xC9,0xFF,//0;"8",8
0xFF,0xD3,0xAD,0xAD,0x8D,0xC3,0xFF,//0;"9",9
};
uchar data_buf[32]={
0xFF,0xC3,0x99,0xBD,0xBD,0x99,0xC3,//0;"0",0
0xFF,0xFF,0xBD,0xBD,0x81,0xBF,0xBF,//0;"1",1
0xBF,0x93,0x9D,0xAD,0xB5,0x99,0xFF,//0;"2",2
0xDF,0xBB,0xAD,0xAD,0xA5,0xC9,0xFF,//0;"3",3
0xff,0xff,0xff,0xff,
};
void hc_595_init(){
SCK=0;
RCK=0;
}
void HC_595_writebyte(unsigned char dat)
{ unsigned char i;
for(i=0;i<8;i++)
{ SER=dat&(0x80>>i);
SCK=1;
SCK=0;
}
//RCK=1;
// RCK=0;
}
void print_screen(){
char j;
unsigned char lie = 0x01;
//uchar wei = 0xf0;
for(j=0;j<8;j++){
LED_DATA = data_buf[j];//data_buf[j];
lie = 0x01<<j;
//for(i = 0; i < 4;i++){
HC_595_writebyte(0x00 );
HC_595_writebyte(0x00);
HC_595_writebyte(0x00);
HC_595_writebyte(lie&0xff);
//}
RCK=1;
RCK=0;
delay_ms(1);
//LED_DATA = 0xff;
}
for(j=0;j<8;j++){
LED_DATA = data_buf[j+8];//data_buf[j];
lie = 0x01<<j;
//for(i = 0; i < 4;i++){
HC_595_writebyte(0x00 );
HC_595_writebyte(0x00);
HC_595_writebyte(lie&0xff);
HC_595_writebyte(0x00);
//}
RCK=1;
RCK=0;
delay_ms(1);
//LED_DATA = 0xff;
}
for(j=0;j<8;j++){
LED_DATA = data_buf[j+16];//data_buf[j];
lie = 0x01<<j;
//for(i = 0; i < 4;i++){
HC_595_writebyte(0x00 );
HC_595_writebyte(lie&0xff);
HC_595_writebyte(0x00);
HC_595_writebyte(0x00);
//}
RCK=1;
RCK=0;
delay_ms(1);
//LED_DATA = 0xff;
}
for(j=0;j<8;j++){
LED_DATA = data_buf[j+24];//data_buf[j];
lie = 0x01<<j;
//for(i = 0; i < 4;i++){
HC_595_writebyte(lie&0xff);
HC_595_writebyte(0x00 );
HC_595_writebyte(0x00);
HC_595_writebyte(0x00);
//}
RCK=1;
RCK=0;
delay_ms(1);
//LED_DATA = 0xff;
}
return;
/*
for(j = 0; j < 8; j++){
//j=2;
LED_DATA = 0xff ^ (0x01<<j);
for(i = 0; i < 4;i++){
HC_595_writebyte(data_buf[i+j*4]);
}
RCK=1;
RCK=0;
delay_ms(1);
for(i = 0; i < 4;i++){
HC_595_writebyte(0x00);
}
RCK=1;
RCK=0;
}*/
}
char miao=0;fen=12;
void show_time(){
char i;
for(i=0;i<32;i++){
data_buf[i] = 0xff;
}
for(i=0; i < 7; i++){
data_buf[i] = font7_8[fen/10][i];
}
for(i=8; i < 15; i++){
data_buf[i] = font7_8[fen%10][i-8];
}
if(miao&0x01){
data_buf[15] = 0x99;
data_buf[16] = 0x99;
}
for(i=17; i < 24; i++){
data_buf[i] = font7_8[miao/10][i-17];
}
for(i=25; i < 32; i++){
data_buf[i] = font7_8[miao%10][i-25];
}
}
void main(void)
{
uchar time= 0;
hc_595_init();
show_time();
while(1){
//HC_595_writebyte(a);
if(time>3){
time = 0;
miao++;
if(miao > 59){
miao = 0;
fen++;
if(fen > 59){
fen = 0;
}
}
show_time();
//LED_DATA = 0xff;
}else{
//LED_DATA = 0x00;
}
//delay_ms(500);
time++;
print_screen();
}
}


IP属地:北京1楼2022-06-04 11:22回复
    新字库
    char code font7_8[10][7]={
    0xFF,0xC3,0x99,0xBD,0xBD,0x99,0xC3,//0;"0",0
    0xFF,0xFF,0xBD,0xBD,0x81,0xBF,0xBF,//0;"1",1
    0xfF,0x93,0x9D,0xAD,0xB5,0x99,0xFF,//0;"2",2
    0xfF,0xBB,0xAD,0xAD,0xA5,0xC9,0xFF,//0;"3",3
    0xfF,0xCF,0xD7,0xDB,0x9B,0x81,0xDF,//0;"4",4
    0xFF,0xd9,0xB5,0xB5,0xB5,0xB5,0xCF,//0;"5",5
    0xFF,0xC7,0xAB,0xB5,0xB5,0xB5,0xCd,//0;"6",6
    0xFF,0xFD,0x9D,0xED,0xF5,0xF9,0xFD,//0;"7",7
    0xFF,0xCB,0xB5,0xB5,0xA5,0xC9,0xFF,//0;"8",8
    0xFF,0xD3,0xAD,0xAD,0x8D,0xC3,0xFF,//0;"9",9
    };


    IP属地:北京2楼2022-06-04 11:31
    回复