📄 main.c
字号:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <MC9S08AW60.h>
//char sensor_temp_disp[]="000.00";
#define LCD_DATA_PORT PTBD
#define RS PTDD_PTDD4
#define RW PTDD_PTDD5
#define EN PTDD_PTDD6
#define LOW 0
#define HIGH 1
#define Clear_screen 0x01
#define Disp_on 0x0c
#define Disp_off 0x08
#define Cursor_on 0x0e
#define Cursor_off 0x0c
#define Cursor_flicker_on 0x0f
#define Cursor_flicker_off 0x0e
void LCD_delay(unsigned char d)
{
while(d--)
{
__RESET_WATCHDOG();
}
}
void MCU_Init(void)
{
ICGC1=0X78;
ICGC2=0X01;
}
void Lcd12864_Write_Data(char Data)
{
RS=HIGH;
RW=LOW;
LCD_DATA_PORT=Data;
LCD_delay(100);
EN=HIGH;
LCD_delay(100);
EN=LOW;
LCD_DATA_PORT=0xFF;
LCD_delay(100);
LCD_delay(100);
}
void Lcd12864_Write_Command(char Command_Code)
{
RS=LOW;
RW=LOW;
LCD_DATA_PORT=Command_Code;
LCD_delay(100);
EN=HIGH ;
LCD_delay(100);
EN=LOW;
LCD_delay(100);
LCD_delay(100);
}
void Lcd12864_set_xy(unsigned char x, unsigned char y)
{
unsigned char p;
switch(x)
{
case 0: p = 0x80; break; //第一行开始地址
case 1: p = 0x88; break; //第二行
case 2: p = 0x90; break; //第三行
case 3: p = 0x98; break; //第四行
}
p += y;
__RESET_WATCHDOG();
Lcd12864_Write_Command(p);
}
void Lcd12864_Write_words(char x, char y, char *str)
{
unsigned char i = 0;
Lcd12864_set_xy(x,y);
while(str[i] != '\0')
{
Lcd12864_Write_Data(str[i++]);
}
}
void Lcd12864_Int(void)
{
LCD_delay(20);
Lcd12864_Write_Command(0x30);
LCD_delay(20);
Lcd12864_Write_Command(Disp_on); /*开显示,不显示光标*/
LCD_delay(20);
Lcd12864_Write_Command(Clear_screen); /*显示清屏。*/
LCD_delay(20);
Lcd12864_set_xy(0,0);
}
void main(void)
{
MCU_Init();
PTBDD=0XFF;
PTDDD=0XFF;
Lcd12864_Int();
Lcd12864_Write_Command(Clear_screen); /*显示清屏。*/
Lcd12864_set_xy(0,0);
Lcd12864_Write_words(0,1,"北京欢迎您!");
Lcd12864_Write_words(1,0,"One word one dream!");
for(;;) {
__RESET_WATCHDOG();
} /* feeds the dog */
/* please make sure that you never leave this function */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -