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

📄 +

📁 基于msp430和1286的红外控制的万年历
💻
字号:
//******************************************************************************
//msp430控制lcd12864 
 
//  2011/2/21 gly 
 
//******************************************************************************
//显示数字时注意转化   后面会有两位乱码
  
#include "lcd12864.h"
#include "delay.h"

 
 
//端口初始化 设置数据和控制位均为输出 
void init_io()
{
  set_3pin_out;//初始化3控制端口为output
  data_out;//数据端口设置为output
}
 
//写一字节的的指令
 void write_onebyte_command(unsigned char onebyte)
{
 
 clr_lcden;
  
  clr_rs;
  clr_rw;
 dataport=onebyte;
 
 set_lcden;
 
 clr_lcden;
 _NOP(); _NOP(); _NOP(); 
}
//写一字节的数据
 void write_onebyte_data(unsigned char onebyte)
{
  clr_lcden;
  
  set_rs;
  clr_rw;
 dataport=onebyte;
 
 set_lcden;
  
 clr_lcden;
 _NOP(); _NOP();  _NOP(); 
}
//初始化lcd12864 按照数据手册即可
void lcd12864_init()
 {
   init_io();
   
   
     write_onebyte_command(0x38);//显示模式设置
     write_onebyte_command(0x08);//显示关闭
     write_onebyte_command(0x01);//显示清屏
     delay_ms(2);
     //delay();//清屏延时 
     write_onebyte_command(0x06);//显示光标移动设置
     write_onebyte_command(0x0c);//显示开及光标设置
}

void lcd12864_clear()
{
  write_onebyte_command(0x01);//显示清屏
     delay_ms(2);
}
 
///确定显示的的位置
void GotoXY(unsigned char hang, unsigned char lie)
{
  unsigned char adress;
  if(hang==0)
    adress=0x80+lie; 
  else if(hang==1)
    adress=0x90+lie;
     else if(hang==2)
     adress=0x88+lie;
       else if(hang==3)
     adress=0x98+lie;
  write_onebyte_command(adress);
     _NOP();
}
//显示字符串
void Print(unsigned char *str)
{
	while(*str!='\0')
	{
           write_onebyte_data(*str);
		str++;
	}
}
//定位 加 显示字符串  
void LCD_Print(unsigned char x, unsigned char y, unsigned char *str)
{
  GotoXY(x,y);
  Print(str);
}
//新加一个可以控制显示的位的个数  一个汉字为两位
void LCD_Print_array(unsigned char x, unsigned char y,unsigned char num, unsigned char *str) 
{
  GotoXY(x,y);
  for(unsigned char i=0;i<num;i++)
	{
           write_onebyte_data(*str);
		str++;
	}
}
 
  //******************************************************************************
   //已经显示数据为0~15 转换成为ASCII   lcd12864显示为0~F
  //行列定位hang lie  hang=0第一行 hang=1第二行 lie=0为第一位 lie=1第3位  
  //stringlength为显示长度  str为显示数据 
  //******************************************************************************
void LCD_Display_String(unsigned char hang,unsigned char lie,unsigned char stringlength,unsigned char *str)
{
  GotoXY(hang,lie);// 确定显示起始位置 
  unsigned char temp;
  for(unsigned char i=0;i<stringlength;i++)
  {
              if(*str<10)
                  {
                    temp=*str+48;//0~9转换为相应的数据ASCII代码
                  }
               else if(*str<16) 
                   {
                     temp=*str+55; //10~15转换为相应的数据ASCII代码
                    }// 0~15 转换成为相应的ASCII代码
                else 
                {
                  temp=*str;
                }
           write_onebyte_data(temp);//写一个字符
		 str++;  //指针加1
  }

}

 


  

⌨️ 快捷键说明

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