#include "stm32f0xx.h" #include "ST7567a.h" #include "stdlib.h" #include <math.h>
extern __IO uint8_t UC1701x_index; extern __IO uint16_t SysTick_count; int ST7567_RefreshFlag=0; int ST7567_BlinkFlag=0; int pwr_offFlag=0; __IO uint8_t ST7567_GRAM[55]; //LCD数据缓冲区总共55个寄存器,分两页显示,第一页0~24,第二页25~50
void Delay_nms(uint16_t nms) {
uint16_t i,j; for(i = 0 ; i < nms ;i++) for(j = 0 ; j <1150 ; j++);
讯享网
} //lcd驱动指令/数据函数 void ST7567_WR_Byte(uint8_t chData, uint8_t chCmd) {
讯享网uint8_t i; ST7567_CS_0; // if(chCmd==1) { ST7567_A0_1;// } else { ST7567_A0_0; } for(i=0;i<8;i++) { ST7567_SCLK_0;// if(chData&0x80) { ST7567_SDIN_1;// } else { ST7567_SDIN_0;// } ST7567_SCLK_1;// chData<<=1; } ST7567_CS_1; // ST7567_A0_1; //
GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
讯享网 GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB,GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// LED_OFF; // LCD_light_1;
讯享网 ST7567_RST_1; Delay_nms(20); ST7567_RST_0; Delay_nms(100); ST7567_RST_1; Delay_nms(20); ST7567_WR_Byte(0xe2, ST7567_CMD);//软复位 Delay_nms(5); ST7567_WR_Byte(0x2c, ST7567_CMD);//内部电源管理 Delay_nms(5); ST7567_WR_Byte(0x2e, ST7567_CMD);//三条指令间隔时间2um Delay_nms(5); ST7567_WR_Byte(0x2f, ST7567_CMD);//电源控制3 电压跟随器打开 Delay_nms(5); ST7567_WR_Byte(0x25, ST7567_CMD);// ST7567_WR_Byte(0x81, ST7567_CMD);//电压模式选择 ST7567_WR_Byte(0x1d, ST7567_CMD);//电压调整寄存器低位 范围0x00-0x3f
// ST7567_WR_Byte(0x22, ST7567_CMD);//电压调整寄存器高位 范围0x21-0x27 值越大,显示效果越浓(底影越浓)LCD电阻率0x20~0x27
ST7567_WR_Byte(0x23, ST7567_CMD);//电压调整寄存器高位 范围0x21-0x27 值越大,显示效果越浓(底影越浓)LCD电阻率0x20~0x27 ST7567_WR_Byte(0xa3, ST7567_CMD);//设置LCD偏置比 A3:1/5(bias) A2:1/6 ST7567_WR_Byte(0xa0, ST7567_CMD);//设置SEG方向镜像选择 0xa0正常 0xa1左右镜像 ST7567_WR_Byte(0xc0, ST7567_CMD);//设置COM方向 0xc0正常 0xc8上下镜像 ST7567_WR_Byte(0x40, ST7567_CMD);//设置滚动行 ST7567_WR_Byte(0xaf, ST7567_CMD);//显示开 ST7567_Clear(0);
} //设置寄存器页地址 void ST7567_Set_Adress(uint8_t chXpos) {
讯享网 ST7567_WR_Byte(0x0f,ST7567_CMD); //设置列地址-低四位 重点 ST7567_WR_Byte(0x10,ST7567_CMD); //设置列地址-高四位 ST7567_WR_Byte(0xb0+chXpos,ST7567_CMD); //设置页地址(0~7)
} //缓冲区数据更新,寄存器数据更新 void ST7567_Refresh_Gram(void) {
uint8_t n; ST7567_Set_Adress(0); for(n=0;n<55;n++) { ST7567_WR_Byte(ST7567_GRAM[n],1); }
} //清屏,缓冲区清零,寄存器清零 void ST7567_Clear(uint8_t a) {
讯享网uint8_t j; ST7567_Set_Adress(0); for(j = 0 ; j < 55 ; j++) { ST7567_WR_Byte(a , ST7567_DATA); ST7567_GRAM[j]=a; } ST7567_Refresh_Gram();
}
void ST7567_Task() {
if(ST7567_RefreshFlag) { ST7567_RefreshFlag=0; ST7567_Refresh_Gram(); } if(pwr_offFlag) { pwr_offFlag = 0;
//// Worng_power_off();
讯享网}
}
void ST7567_TaskTrig(int BlinkFlag) {
ST7567_BlinkFlag = BlinkFlag; ST7567_RefreshFlag = 1;
}
void pwr_offTrig() {
讯享网pwr_offFlag =1;
}
void ST7567_battery_show() {
ST7567_GRAM[0]=0xea; ST7567_Refresh_Gram();
} void ST7567_disk_show() {
讯享网ST7567_GRAM[1]=0xd5; ST7567_GRAM[2]=0xc5; ST7567_Refresh_Gram();
} void ST7567_memory_show() {
ST7567_GRAM[3]=0x7d; ST7567_GRAM[4]=0xd4; ST7567_GRAM[5]=0x55; ST7567_GRAM[6]=0x54; ST7567_Refresh_Gram();
} void ST7567_laser_show() {
讯享网ST7567_GRAM[7]=0xf0; ST7567_GRAM[8]=0x15; ST7567_GRAM[9]=0x54; ST7567_GRAM[10]=0xd5; ST7567_GRAM[11]=0x44; ST7567_Refresh_Gram();
} void ST7567_temperature_show() {
ST7567_GRAM[11]|=0x01; ST7567_GRAM[12]|=0x15; ST7567_GRAM[14]|=0x55; ST7567_GRAM[15]|=0x15; ST7567_GRAM[16]|=0x55; ST7567_Refresh_Gram();
} void ST7567_image_show() {
讯享网ST7567_GRAM[12]|=0xea; ST7567_GRAM[14]|=0xaa; ST7567_GRAM[15]|=0xea; ST7567_GRAM[16]|=0x80; ST7567_Refresh_Gram();
} void ST7567_symbol_show() {
ST7567_GRAM[11]|=0xb0;//H5 T41 T44 ST7567_GRAM[16]|=0x2a;//T48 T46 T49 ST7567_GRAM[17]|=0x40;//H6 ST7567_GRAM[54]|=0x81;//T42 T45 ST7567_GRAM[13]|=0x02;//H7 ST7567_Refresh_Gram();
} //lcd 数字0~9显示 组合编码 适用于第一行 1-5数码管 const unsigned char ascii_num1_1[10]={0xaa,0x28,0x8a,0xaa,0x28,0xa2,0xa2,0x2a,0xaa,0xaa};
讯享网 // 0 1 2 3 4 5 6 7 8 9
const unsigned char ascii_num1_2[10]={0x22,0x00,0x28,0x08,0x0a,0x0a,0x2a,0x00,0x2a,0x0a}; //适用于第二行 6-10数码管 const unsigned char ascii_num2_1[10]={0x55,0x14,0x51,0x55,0x14,0x45,0x45,0x54,0x55,0x55};
// 0 1 2 3 4 5 6 7 8 9
const unsigned char ascii_num2_2[10]={0x44,0x00,0x14,0x10,0x50,0x50,0x54,0x00,0x54,0x50}; //适用于第三行 11-15数码管 const unsigned char ascii_num3_1[10]={0x11,0x00,0x14,0x04,0x05,0x05,0x15,0x00,0x15,0x05};
讯享网 // 0 1 2 3 4 5 6 7 8 9
const unsigned char ascii_num3_2[10]={0x55,0x14,0x45,0x55,0x14,0x51,0x51,0x15,0x55,0x55}; //适用于第四行 16-20数码管 const unsigned char ascii_num4_1[10]={0x88,0x00,0x28,0x20,0xa0,0xa0,0xa8,0x00,0xa8,0xa0};
// 0 1 2 3 4 5 6 7 8 9
const unsigned char ascii_num4_2[10]={0xaa,0x28,0xa2,0xaa,0x28,0x8a,0x8a,0xa8,0xaa,0xaa}; //适用于第21号小数码管 const unsigned char ascii_num5_1[10]={0xaa,0x28,0x8a,0xaa,0x28,0xa2,0xa2,0x2a,0xaa,0xaa};
讯享网 // 0 1 2 3 4 5 6 7 8 9
const unsigned char ascii_num5_2[10]={0x88,0x00,0xa0,0x20,0x28,0x28,0xa8,0x00,0xa8,0x28}; //适用于第22,23,24小数码管 const unsigned char ascii_num6_1[10]={0xaa,0x28,0x8a,0xaa,0x28,0xa2,0xa2,0x2a,0xaa,0xaa};
// 0 1 2 3 4 5 6 7 8 9
const unsigned char ascii_num6_2[10]={0x22,0x00,0x28,0x08,0x0a,0x0a,0x2a,0x00,0x2a,0x0a}; //适用于第25号小数码管 const unsigned char ascii_num7_1[10]={0x55,0x14,0x51,0x55,0x14,0x45,0x45,0x54,0x55,0x55};
讯享网 // 0 1 2 3 4 5 6 7 8 9
const unsigned char ascii_num7_2[10]={0x11,0x00,0x05,0x04,0x14,0x14,0x15,0x00,0x15,0x14}; //适用于第26,27,28小数码管 const unsigned char ascii_num8_1[10]={0x55,0x14,0x51,0x55,0x14,0x45,0x45,0x54,0x55,0x55};
// 0 1 2 3 4 5 6 7 8 9
const unsigned char ascii_num8_2[10]={0x44,0x00,0x14,0x10,0x50,0x50,0x54,0x00,0x54,0x50}; //适用于第29号小数码管 const unsigned char ascii_num9_1[10]={0x44,0x00,0x50,0x10,0x14,0x14,0x54,0x00,0x54,0x14};
讯享网 // 0 1 2 3 4 5 6 7 8 9
const unsig

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/141149.html