#include <reg52.h>
#include <intrins.h>
//????
sbit SCL = P1^0; // ????
sbit SI = P1^1; // ????
sbit A0 = P1^2; // ??/????
sbit CS1 = P1^3; // ??1
sbit RES = P1^4; // ??
//??????
#define LCD_WIDTH 128
#define LCD_HEIGHT 64
#define LCD_PAGES (LCD_HEIGHT/8)
//????
void delay_us(unsigned int t) { while(t--); }
void delay_ms(unsigned int t) {
unsigned int i, j;
for(i=0; i<t; i++)
for(j=0; j<120; j++);
}
//??????
void write_byte(unsigned char dat) {
unsigned char i;
for(i=0; i<8; i++) {
SCL = 0;
SI = (dat & 0x80) ? 1 : 0; // ????
dat <<= 1;
SCL = 1;
_nop_();
}
SCL = 0;
}
//????
void send_cmd(unsigned char cmd) {
CS1 = 0; // ????
A0 = 0; // ????
write_byte(cmd);
CS1 = 1; // ????
}
//????
void send_data(unsigned char dat) {
CS1 = 0; // ????
A0 = 1; // ????
write_byte(dat);
CS1 = 1; // ????
}
//LCD???
void lcd_init() {
RES = 0; // ????
delay_ms(10);
RES = 1;
delay_ms(10);
send_cmd(0xE2); // ????
delay_ms(10);
send_cmd(0xA2); // ?????(1/9 bias)
send_cmd(0xA1); // SEG????
send_cmd(0xC0); // COM????
send_cmd(0x24); // ?????
send_cmd(0x81); // ??????
send_cmd(0x20); // ???
send_cmd(0x2F); // ????(??????)
send_cmd(0x40); // ???????0
send_cmd(0xAF); // ????
}
//??????
void set_pos(unsigned char page, unsigned char column) {
send_cmd(0xB0 | (page & 0x0F)); // ???
send_cmd(0x10 | ((column >> 4) & 0x0F)); // ????4?
send_cmd(0x00 | (column & 0x0F)); // ????4?
}
//??
void clear_screen() {
unsigned char i, j;
for(i=0; i<LCD_PAGES; i++) {
set_pos(i, 0);
for(j=0; j<LCD_WIDTH; j++) {
send_data(0x00);
}
}
}
// ??????(??????????)
void display_partial_image(unsigned char page, unsigned char col,
const unsigned char *img_data,
unsigned char width, unsigned char height_pages) {
unsigned char p, c;
for(p=0; p<height_pages; p++) {
set_pos(page + p, col);
for(c=0; c<width; c++) {
send_data(img_data[p*width + c]);
}
}
}
code unsigned char smile_32x32_negative[] =
{
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,0x00,0x00,0x00,0x80,0x00,0x00,0x80,
0xC0,0xE0,0xE0,0xE0,0xA0,0xA0,0xE0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF8,0xF8,0xF8,
0xF8,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xF8,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
0xFC,0xFC,0xFC,0xFC,0xF8,0xF8,0xF0,0xF0,0xF0,0xF8,0xF8,0xF8,0xF8,0xF0,0xF0,0xF0,
0xF0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xA0,0x20,0x60,0x40,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF0,0xF8,0xF9,0xFD,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xBE,0x24,0x60,0x40,
0xC0,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,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x40,0x03,0x0F,0x3F,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0x7F,0x3F,0x07,0x01,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x03,0x03,0x03,0x07,0x07,0x07,0x07,0x07,0x07,
0x07,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x07,0x07,0x07,0x07,0x07,0x07,
0x07,0x07,0x07,0x07,0x07,0x07,0x0F,0x0F,0x0F,0x1F,0x3F,0x7F,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0x7F,0x7F,0x3F,0x1F,0x0E,0x00,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x08,0x00,0x03,0x0F,0x1F,
0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x0C,0x0C,0x2C,0x2C,0x3C,0x3C,0x1C,
0x38,0x38,0x38,0x38,0x38,0x38,0x18,0x18,0x58,0x18,0x18,0x10,0x10,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0xE0,0xE0,0x60,0xD0,0xD8,0x78,0x78,0x38,0x78,0x78,0x78,0x78,
0x78,0x38,0xB8,0xF8,0x78,0x78,0x18,0x18,0x18,0x1C,0x1C,0x18,0x08,0x00,0x61,0x7F,
0x7F,0x7F,0x7F,0x7F,0x3F,0x1F,0x03,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xE0,
0xE0,0xE0,0xE0,0xC0,0x80,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,0x00,0x00,
0x00,0x40,0x40,0x4C,0x7F,0x7F,0x7F,0x79,0x70,0x70,0x70,0x30,0x20,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x20,0x30,0x10,0x98,0xC8,0xE0,0xE8,0xE0,0xE0,0xC0,0xC0,0xC0,
0xC0,0xC0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x78,0xF8,0xFC,0xFC,0xFC,0xFC,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF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xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x9F,0x1F,
0x00,0x00,0x01,0x01,0x01,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x07,0x0F,0x2D,
0x24,0x43,0x4B,0x5E,0x5E,0x18,0x38,0x38,0x30,0x30,0x60,0x60,0x60,0xC0,0xC0,0xC0,
0x80,0x80,0x80,0xC0,0xC0,0xC0,0x60,0x60,0x20,0x30,0x70,0x90,0x90,0x10,0x10,0x10,
0x10,0x98,0x98,0x88,0x88,0x8C,0x8C,0x84,0xC6,0xC2,0xC2,0xE3,0xE1,0xE1,0xF0,0xF8,
0xF8,0xFC,0xFC,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFD,0xFD,0xFE,0xFF,
0x7E,0x79,0x3F,0x1F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,0x3F,0x3F,0x3F,0x1F,0x0};/*"?????",0*/
// ?????(????)
code unsigned char FONT_TABLE[37][5] =
{
// ???? A-Z
{0x7C,0x12,0x11,0x12,0x7C}, // A
{0x7F,0x49,0x49,0x49,0x36}, // B
{0x3E,0x41,0x41,0x41,0x22}, // C
{0x7F,0x41,0x41,0x22,0x1C}, // D
{0x7F,0x49,0x49,0x49,0x41}, // E
{0x7F,0x09,0x09,0x09,0x01}, // F
{0x3E,0x41,0x49,0x49,0x7A}, // G
{0x7F,0x08,0x08,0x08,0x7F}, // H
{0x00,0x41,0x7F,0x41,0x00}, // I
{0x20,0x40,0x41,0x3F,0x01}, // J
{0x7F,0x08,0x14,0x22,0x41}, // K
{0x7F,0x40,0x40,0x40,0x40}, // L
{0x7F,0x02,0x0C,0x02,0x7F}, // M
{0x7F,0x04,0x08,0x10,0x7F}, // N
{0x3E,0x41,0x41,0x41,0x3E}, // O
{0x7F,0x09,0x09,0x09,0x06}, // P
{0x3E,0x41,0x51,0x21,0x5E}, // Q
{0x7F,0x09,0x19,0x29,0x46}, // R
{0x26,0x49,0x49,0x49,0x32}, // S
{0x01,0x01,0x7F,0x01,0x01}, // T
{0x3F,0x40,0x40,0x40,0x3F}, // U
{0x1F,0x20,0x40,0x20,0x1F}, // V
{0x3F,0x40,0x38,0x40,0x3F}, // W
{0x63,0x14,0x08,0x14,0x63}, // X
{0x07,0x08,0x70,0x08,0x07}, // Y
{0x61,0x51,0x49,0x45,0x43}, // Z
// ?? 0-9
{0x3E,0x45,0x49,0x51,0x3E}, // 0
{0x00,0x21,0x7F,0x01,0x00}, // 1
{0x21,0x43,0x45,0x49,0x31}, // 2
{0x42,0x41,0x51,0x69,0x46}, // 3
{0x0C,0x14,0x24,0x7F,0x04}, // 4
{0x72,0x51,0x51,0x51,0x4E}, // 5
{0x1E,0x29,0x49,0x49,0x06}, // 6
{0x40,0x47,0x48,0x50,0x60}, // 7
{0x36,0x49,0x49,0x49,0x36}, // 8
{0x30,0x49,0x49,0x4A,0x3C}, // 9
// ????(??)
{0x00,0x00,0x00,0x00,0x00} // ??(??36)
};
// ?????(???0-7,???0-131)
void display_string(unsigned char page, unsigned char start_col, char *str) {
unsigned char c_idx,i;
while(*str != '\0') {
char c = *str++;
// ????(??????????)
if(c >= 'A' && c <= 'Z') c_idx = c - 'A';
else if(c >= 'a' && c <= 'z') c_idx = c - 'a'; // ?????
else if(c >= '0' && c <= '9') c_idx = 26 + (c - '0');
else if(c == ' ') c_idx = 36;
else continue; // ???????
// ????
if(c_idx >= 37) continue;
// ???????????
set_pos(page, start_col);
for( i=0; i<5; i++) {
send_data(FONT_TABLE[c_idx][i]);
}
send_data(0x00); // ??????
start_col += 6; // ?????6?(5??+1??)
// ????(132???)
if(start_col > 126) break; // 132-6=126????????
}
}
void main() {
lcd_init();
clear_screen();
// ????
display_partial_image(0, 0, smile_32x32_negative, 128, 8); // ?3,?60
// ??????
// display_string(1, 10, "Hello BEAT");
while(1);
}修改改代码使单片机 STC15W4K32S4 通过控制OK BACK DOWN这三个按键控制显示屏显示三级菜单,最开始lcd上按列显示RUN STOP ,最开始光标在RUN上当我按下DOWN按键时,光标向下移动到STOP,当我在RUN下按下OK按键时,进入RUN子菜单,当本次按下时间不超过两秒,lcd上按列显示“OKshort ”,当本次按下的时间超过2s时,显示“OKlong runing”,当我在STOP下按下OK按键时,进入STOP子菜单,当本次按下时间不超过两秒,lcd上按列显示“STOPshort ”,当本次按下的时间超过2s时,显示“STOPlong stopping 当我按下BACK按键时,返回到最初页面,帮我生成程序代码Protues仿真