⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 多点烟雾,温度探测报警程序 基于MSP430F247,485总线.
💻 C
字号:

#include<msp430x24x.h>
#include"LCD.h"

//下面是LCD的子程序
/******************************************************************  
// 硬件连接信息(调试液晶是南京奥雪公司的20*4)
//  1--VSS    GND            
//  2--VDD    VCC        
//  3--V0     至地
//  4--RS     数据/命令选择
//  5--R/W    读写控制
//  6--E      使能
//  7--DB0    DB0
//  14-DB7    DB7
//  15-LEDA   背光正  
//  16-LEDK   背光负(接地) 
//
//  硬件上需要修改的话,有两个函数需要改动
//  LCD_Busy() 读忙函数
//  LCD_Init() 初始化函数
*******************************************************************/
void LCD_init(void)
{  
 LCD_delay_nms();
 P2DIR |= 0xff;           
 P1DIR |= 0xff;   
 LCD_en_command(0x0C);
 LCD_en_command(0x06);
 LCD_en_command(0x80);
 LCD_en_command(0x38);
 LCD_en_command(0x01);
}

/********************************************************************/

void LCD_Busy(void)
{
    char BF = 0;    //  busy flag
    CLR_LCD_RS;
    SET_LCD_RW;
    P2DIR = 0x00;   //  modify this if you change hardware
    do
    {
     SET_LCD_EN;
        BF = P2IN;
        CLR_LCD_EN;
    } while(BF & 0x80);
    P2DIR = 0xff;   //  modify this if you change hardware
}
/********************************************************************/
void LCD_delay(void)
{
 unsigned int i;
 for(i=500;i>0;i--);     // need modify this time at differert mcu
}
/********************************************************************/  
void LCD_en_command(unsigned char command)
{
 LCD_Busy();
 CLR_LCD_RS;
 CLR_LCD_RW;
 SET_LCD_EN;
 LCD_I0=command;
 CLR_LCD_EN;
}
/********************************************************************/
void LCD_en_dat(unsigned char dat)
{
 LCD_Busy();
 SET_LCD_RS;
 CLR_LCD_RW;
 SET_LCD_EN;
 LCD_I0=dat;
 CLR_LCD_EN;
}
/********************************************************************/
void LCD_set_xy( unsigned char x, unsigned char y )  
{
     unsigned char address;
     switch (y) 
        {
          case 0:
                address = 0x80 + x;break;
          case 1: 
                address = 0xC0 + x;break;
          case 2:
                address = 0x94 + x;break;
          case 3:
                address = 0xD4 + x;break;
        }
     LCD_en_command(address); 
}
/********************************************************************/
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
{
 LCD_set_xy( x, y ); 
 LCD_en_dat(dat);
}
/********************************************************************/
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
    LCD_set_xy( X, Y );  
    while (*s) 
    {
     LCD_I0=*s;
     LCD_en_dat(*s);   
     s ++;
    }
}
void LCD_delay_nms(void)       
{
    unsigned int count,i;
    for(count = 4; count > 0; count--)
   for(i=50000;i>0;i--);  
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -