#include //管脚宏定义 #define SCLK 0x01<<24 //595时钟端 #define MISO 0x01<<5 //数据输入端 #define MOSI 0x01<<6 //数据输出端 #define RCK 0x01<<7 //SO12864时钟输入端 //LCD Define #define LCD_A 1<<30 //命令数据选择端,高电平:数据 低电平:命令 #define LCD_CLK 1<<4 //时钟端 #define LCD_DATA MOSI //数据端 #define B_LED 1<<13 //背光 #define Sclk_L() IO0CLR |=LCD_CLK //时钟高电平 #define Sclk_H() IO0SET |=LCD_CLK //时钟低电平 #define Res_L() HC595_DATA &=~(1<<2);Write595() //复位低电平 #define Res_H() HC595_DATA |=(1<<2); Write595() //复位高电平 #define Data_L() IO0CLR |=LCD_DATA //数据低电平 #define Data_H() IO0SET |=LCD_DATA //数据高电平 #define CS_L() HC595_DATA &=~1; Write595() //片选低电平 #define CS_H() HC595_DATA |=1; Write595() //片选高电平 #define Write_C() IO0CLR |=LCD_A //选择写命令 #define Write_D() IO0SET |=LCD_A //选择写数据 #define Writecommand //#define pgm_read_byte //#define LcdCls #define Fosc 11059200 #define Fcclk (Fosc * 4) #define Fpclk (Fcclk / 4) * 1 unsigned int datas; unsigned int times; unsigned int bak; //函数声明 void Delayn(unsigned long n); void Write595(); void HC595_Init(void); void Lcd_Init(void); void Lcd_display_HZ(unsigned char x,unsigned char y,unsigned char *p); void LcdCls(unsigned char data); void Setxy(unsigned char x,unsigned char y); void show_string1616(unsigned char x,unsigned char y,unsigned *string,unsigned char string_lenth); void RTCInit (void); void SendTimeRtc(void); void LcdShow1216(unsigned char x,unsigned char y,unsigned char *p); //全局变量 unsigned int HC595_DATA=0xFFFFFFFF; unsigned int title[]={19,19,8,20,21};//"小小日历钟",取的值是由模中各个字所在的位置决定的 unsigned char HZ[][32]= {{0x20,0x24,0x24,0x24,0xFE,0x23,0x22,0x20,0xFF,0x20,0x22,0xAC,0x20,0x30,0x20,0x00, 0x00,0x08,0x48,0x84,0x7F,0x02,0x21,0x10,0x09,0x06,0x1A,0x61,0x80,0xE0,0x00,0x00}, //"我"(0) {0x00,0xFC,0xFC,0x84,0x84,0xFE,0xFE,0x14,0x90,0x10,0x10,0xFF,0xFF,0x10,0x18,0x00, 0x00,0x3F,0x1F,0x10,0x10,0x3F,0x3F,0x00,0x00,0x23,0x60,0xFF,0x7F,0x00,0x00,0x00}, //时(1) {0x40,0x20,0xF8,0x07,0x40,0x20,0x18,0x0F,0x08,0xC8,0x08,0x08,0x28,0x18,0x00,0x00, 0x00,0x00,0xFF,0x00,0x00,0x08,0x04,0x43,0x80,0x7F,0x00,0x01,0x06,0x0C,0x00,0x00}, //"你"(2) {0x00,0x20,0x18,0xCF,0xC7,0x44,0x44,0xFC,0xFC,0x44,0x44,0x64,0x46,0x04,0x00,0x00, 0x04,0x04,0x04,0x07,0x07,0x04,0x04,0xFF,0xFF,0x04,0x04,0x04,0x04,0x06,0x04,0x00}, //年(3) {0x00,0x00,0x00,0x00,0xFF,0xFE,0x22,0x22,0x22,0x22,0x22,0xFF,0xFE,0x04,0x00,0x00, 0x00,0x80,0x40,0x70,0x1F,0x07,0x02,0x02,0x02,0x42,0x42,0xFF,0x7F,0x00,0x00,0x00}, //月(4) {0x10,0x90,0xFF,0x50,0x98,0xC8,0x48,0xC8,0x48,0x7F,0x48,0xC8,0x48,0xEC,0x48,0x00, 0x02,0x01,0xFF,0x00,0x00,0xFF,0x10,0x12,0x13,0x7E,0x13,0x52,0x90,0x7F,0x00,0x00}, //"楠"(5) {0x00,0x42,0x82,0x02,0x02,0xFE,0x02,0x02,0x02,0xFE,0x02,0x02,0xC3,0x82,0x00,0x00, 0x40,0x40,0x41,0x46,0x40,0x7F,0x40,0x40,0x40,0x7F,0x44,0x43,0x40,0x60,0x40,0x00}, //"亚"(6) {0x40,0xB0,0x92,0x96,0x9A,0x92,0xF2,0x9E,0x92,0x91,0x99,0x95,0x91,0x50,0x30,0x00, 0x00,0x00,0x40,0x30,0x8C,0x83,0x46,0x2A,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,0x00}, //"爱"(7) {0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFF,0x02,0x00,0x00,0x00, 0x00,0x00,0x00,0x7F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00,0x00,0x00}, //"日"(8) {0x00,0xFC,0x84,0x84,0x84,0xFE,0x14,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x00, 0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x00,0x23,0x40,0x80,0x7F,0x00,0x00,0x00}, //"时"(9) {0x00,0x80,0x40,0x20,0x98,0x86,0x80,0x80,0x83,0x8C,0x90,0x20,0xC0,0x80,0x80,0x00, 0x01,0x00,0x80,0x40,0x20,0x1F,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x01,0x00,0x00}, //"分"(10) {0x20,0x24,0x24,0xA4,0xFE,0xA3,0x22,0x80,0x70,0x00,0xFF,0x00,0x10,0x20,0x60,0x00, 0x10,0x08,0x06,0x01,0xFF,0x00,0x81,0x80,0x40,0x20,0x17,0x08,0x04,0x03,0x00,0x00}, //"秒"(11) {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //"一"(12) {0x40,0x48,0x48,0x48,0xFF,0x48,0x48,0x00,0xC4,0x44,0x44,0x44,0xFE,0x04,0x00,0x00, 0x40,0x20,0x1F,0x20,0x7F,0x42,0x42,0x40,0x47,0x48,0x48,0x48,0x48,0x6E,0x20,0x00}, //"起"(13) {0x00,0x04,0x24,0x24,0x24,0x24,0x24,0xFC,0x22,0x22,0x22,0x33,0x22,0x00,0x00,0x00, 0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x03,0x02,0x00}, //"手"(14) {0x10,0x10,0x10,0xFF,0x90,0x50,0x08,0xE8,0x09,0x0E,0x08,0x08,0xEC,0x08,0x00,0x00, 0x02,0x42,0x81,0x7F,0x00,0x40,0x40,0x40,0x4F,0x60,0x58,0x47,0x40,0x60,0x40,0x00}, //"拉"(15) {0x40,0x20,0xF8,0x07,0x00,0xF8,0x02,0x04,0x08,0x04,0x04,0x04,0x04,0xFE,0x04,0x00, 0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00}, //"们"(16) {0x40,0x40,0x48,0x48,0x48,0x48,0x7F,0xC8,0x4C,0x68,0x50,0x48,0x4C,0x60,0x40,0x00, 0x40,0x20,0x10,0x08,0x04,0x7E,0x91,0x90,0x88,0x88,0x84,0x86,0x80,0xE0,0x00,0x00}, //"老"(17) {0x00,0x84,0xC9,0x22,0x06,0x80,0x7E,0x12,0x32,0x52,0x9F,0x52,0x32,0x0A,0x06,0x00, 0x04,0x04,0x87,0x84,0x4D,0x54,0x26,0x24,0x26,0x55,0x4C,0x85,0x06,0x06,0x04,0x00}, //"婆"(18) {0x00,0x00,0x00,0x00,0x80,0x60,0x00,0xFF,0x00,0x20,0x40,0x80,0x00,0x00,0x00,0x00, 0x00,0x08,0x04,0x02,0x01,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x06,0x00,0x00}, //"小"(19) {0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x43,0xE2,0x40,0x00, 0x40,0x30,0x0F,0x80,0x40,0x20,0x18,0x07,0x00,0x20,0x40,0x80,0x40,0x3F,0x00,0x00}, //"历"(20) {0x80,0x40,0x70,0xCF,0x48,0x48,0x00,0xF0,0x10,0x10,0xFF,0x10,0x10,0xF8,0x10,0x00, 0x02,0x02,0x02,0x7F,0x22,0x12,0x00,0x07,0x02,0x02,0xFF,0x02,0x02,0x07,0x00,0x00}, //"钟"(21) }; unsigned char num1216[][24]= //下面的字模怎么得到的? 畔畔字模软件里面没有1216点阵的数字 { {0x00,0xFC,0xFE,0x06,0x06,0x86,0x46,0x26,0x16,0xFE,0xFC,0x00,0x00,0x3F,0x7F,0x68,0x64,0x62, 0x61,0x60,0x60,0x7F,0x3F,0x00},//0 {0x00,0x00,0x00,0x00,0x08,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F, 0x7F,0x00,0x00,0x00,0x00,0x00}, //1 {0x00,0x3C,0x3E,0x06,0x06,0x06,0x06,0x86,0xC6,0x7E,0x3C,0x00,0x00,0x60,0x70,0x78,0x6C,0x66, 0x63,0x61,0x60,0x60,0x60,0x00}, //2 {0x00,0x3C,0x3E,0x06,0x06,0xC6,0xC6,0xC6,0xC6,0xFE,0x3C,0x00,0x00,0x3C,0x7C,0x60,0x60,0x60, 0x60,0x60,0x60,0x7F,0x3F,0x00}, //3 {0x00,0x00,0x80,0xE0,0x78,0x1E,0x06,0xFE,0xFE,0x00,0x00,0x00,0x00,0x1E,0x1F,0x19,0x18,0x18, 0x18,0x7F,0x7F,0x18,0x18,0x00}, //4 {0x00,0xFE,0xFE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x86,0x00,0x00,0x3C,0x7C,0x60,0x60,0x60, 0x60,0x60,0x60,0x7F,0x3F,0x00}, //5 {0X00,0xFC,0xFE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xCE,0x8C,0x00,0x00,0x3F,0x7F,0x60,0x60,0x60, 0x60,0x60,0x60,0x7F,0x3F,0x00}, //6 {0x00,0x1E,0x1E,0x06,0x06,0x06,0x06,0x86,0xE6,0x7E,0x1E,0x00,0x00,0x00,0x00,0x00,0x60,0x78, 0x1E,0x07,0x01,0x00,0x00,0x00}, //7 {0x00,0x7C,0xFE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xFE,0x7C,0x00,0x00,0x3F,0x7F,0x60,0x60,0x60, 0x60,0x60,0x60,0x7F,0x3F,0x00}, //8 {0x00,0xFC,0xFE,0x06,0x06,0x06,0x06,0x06,0x06,0xFE,0xFC,0x00,0x00,0x31,0x73,0x63,0x63,0x63, 0x63,0x63,0x63,0x7F,0x3F,0x00}, //9 {0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x00}, //- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00}, //space {0x00,0x00,0x00,0x00,0x18,0x3C,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00}, //. }; //主函数 int main(void) { HC595_Init(); //初始化74HC595 IO0DIR |=LCD_A|B_LED|LCD_CLK; //初始化IO口 Lcd_Init(); //初始化液晶屏 LcdCls(0x00);//清屏 Delayn(10000000); RTCInit(); show_string1616(16,0,title,5); while(1) { while(0==(ILR&0x01)); ILR=0x01; SendTimeRtc(); } } //初始化595接口 void HC595_Init(void) { IO0DIR |= MOSI|RCK; IO1DIR |= SCLK; IO1CLR |= SCLK; IO0DIR |= RCK; HC595_DATA =0xFFFFFFFF;Write595(); } //写字节 void WriteByte(unsigned char data) { unsigned char i; //IO0CLR; for(i=0;i<8;i++) { if(data&0x01) IO0SET=MOSI; else IO0CLR =MOSI; IO1SET=SCLK; data>>=1; IO1CLR=SCLK; } //IO0SET=RCK; } //刷新595的数据 void Write595() { IO0CLR=RCK; WriteByte(HC595_DATA&0xff); WriteByte((HC595_DATA&0xff00)>>8); WriteByte((HC595_DATA&0xff0000)>>16); WriteByte((HC595_DATA&0xff000000)>>24); IO0SET=RCK; } //延时周期数 void Delayn(unsigned long n) { while(n--); } void LCDWriteByte(unsigned char data) { unsigned char i,s; s=data; for(i=0;i<8;i++) { //Delayn(1000000); //自己加的 if(s&0x80) Data_H(); else Data_L(); Sclk_H(); s<<=1; Sclk_L(); } } //向液晶屏写数据 void WriteData(unsigned char Data) { Write_D(); CS_L(); LCDWriteByte(Data); CS_H(); } //向液晶屏写命令 void WriteCommand(unsigned char Command) { Write_C(); CS_L(); LCDWriteByte(Command); CS_H(); } //打开液晶背光 0:关闭 1:打开 void Lcd_BackLed(unsigned char on) { if(on==1) { IO0CLR=B_LED; //打开背光 } else if(on==0) { IO0SET=B_LED; //关闭背光 } } //液晶复位 void Lcd_Reset(void) { Res_L(); Delayn(10000000); Res_H(); } //列顺序翻转,左右翻转 0:正常 1:翻转 void Lcd_ColRev(unsigned char i) { WriteCommand(0xa0|(i&0x01)); } //清屏 void LcdCls(unsigned char data) { unsigned char i,j; for(i=0;i<9;i++) { Setxy(0,i); for(j=0;j<128;j++) { WriteData(data); } } } //液晶初始化 void Lcd_Init(void) { Lcd_Reset(); //液晶复位 //Lcd_BackLed(0); Lcd_BackLed(1); //打开液晶背光
上一篇:串口调试助手出现乱码
下一篇:arm 力天电子lpc2148无字库12864显示多行多个汉字(串行)
推荐阅读最新更新时间:2024-11-02 12:23
设计资源 培训 开发板 精华推荐
- EPB-INBX32V3251DA_ConPanel
- 比赛练习
- DC1333A、LTC2640 12 位无缓冲 SPI DAC,具有集成参考板
- 【训练营_进阶班】智能物联网
- 具有低电池电量指示的 MCP1259 稳压 3.3V、低纹波电荷泵和低工作电流睡眠模式或旁路模式的典型应用
- LDK130M18R 1.8V、300 mA 低静态电流、极低噪声 LDO 的典型应用固定版本电路
- 征集令 |物联网智能喂食器
- 使用 ams AG 的 AS1312-BTDT-50 的参考设计
- 用于 MC9S08DZ60 微控制器的 DEMO9S08DZ60、S08D 系列演示板
- LTC3633AIUFD-1 1.2V/1.8V 降压稳压器的典型应用电路,具有一致跟踪和 6V 输入 UVLO