您当前的位置:五五电子网电子知识单片机-工控设备51单片机诺基亚5110显示屏51单片机驱动程序 正文
诺基亚5110显示屏51单片机驱动程序

诺基亚5110显示屏51单片机驱动程序

点击数:7524 次   录入时间:03-04 11:55:44   整理:http://www.55dianzi.com   51单片机
#include <stc.h>
#include "intrins.h"                      //_nop_();延时函数用
#include <dmb.h>                          //字符代码表
#define  uchar unsigned char
#define  uint  unsigned int


sbit    sce = P3^4;  //片选
sbit    res = P0^0;  //复位,0复位
sbit    dc  = P3^5;  //1写数据,0写指令
sbit    SDIn = P3^7;  //数据
sbit    sclk = P3^6;  //时钟
uint data data[2]={0x00,0x00};             //读出温度暂放
//================18b20数据口定义===============
sbit     DQ=P0^0;                               //温度输入口
uint     h; 
uint     temp;
unsigned char presence,flash=0;
/*****************延时函数*************************/
void delay(uint t)
{
  for (;t>0;t--);
}
//================延时函数=====================
void delay_1ms(void)//1ms延时函数
 {
  unsigned int i;
  for (i=0;i<500;i++);
 }

/*---------------LCD显示函数开始----------------
LCD_write_byte: 使用SPI接口写数据到LCD
输入参数:dt:写入的数据;
command :写数据/命令选择;
编写日期:20080918 
----------------------------------------------*/
void LCD_write_byte(unsigned char dt, unsigned char command)
{
 unsigned char i; 
 sce=0; 
 dc=command; 
 for(i=0;i<8;i++)
  { 
   if(dt&0x80)
   sdin=1;
   else
   sdin=0;
   dt=dt<<1;  
   sclk=0;   
   sclk=1; 
  } 
 dc=1; 
 sce=1; 
 sdin=1;
}
/*---------------------------------------
LCD_init: 5110LCD初始化
编写日期:20080918 
-----------------------------------------  */
void LCD_init(void)
{
 res=0;   
   delay_1ms();
   res=1;  
 LCD_write_byte(0x21,0);//初始化Lcd,功能设定使用扩充指令
 LCD_write_byte(0xd0,0);//设定液晶偏置电压
 LCD_write_byte(0x20,0);//使用基本指令
 LCD_write_byte(0x0C,0);//设定显示模式,正常显示
}
/*-------------------------------------------
LCD_set_XY: 设置LCD坐标函数
输入参数:X:0-83  Y:0-5
编写日期:20080918 
---------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
 LCD_write_byte(0x40 | Y, 0);// column
 LCD_write_byte(0x80 | X, 0);// row

/*------------------------------------------
LCD_clear: LCD清屏函数
编写日期:20080918 
--------------------------------------------*/
void LCD_clear(void)
{
 unsigned char t;
 unsigned char k;
 LCD_set_XY(0,0);
  for(t=0;t<6;t++)
  { 
   for(k=0;k<84;k++)
   { 
   LCD_write_byte(0x00,1);  
   } 
  }
}
/*---------------------------------------------
LCD_write_shu: 显示8(宽)*16(高)点阵列数字字母符号等半角类
输入参数:c:显示的字符;
编写日期:20080918 
-----------------------------------------------*/
void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
 unsigned char i;   
 
 LCD_set_XY(row*8, page);// 列,页 
 for(i=0; i<8;i++) 
  {
  LCD_write_byte(shuzi[c*16+i],1); 
  }
  
    LCD_set_XY(row*8, page+1);// 列,页 
 for(i=8; i<16;i++) 
  {
  LCD_write_byte(shuzi[c*16+i],1);
  }   
}
/*---------------------------------------------
LCD_write_hanzi: 显示16(宽)*16(高)点阵列汉字等半角类
输入参数:c:显示的字符;
编写日期:20080918 
-----------------------------------------------*/
void LCD_write_hanzi(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
 unsigned char i;   
 
 LCD_set_XY(row*8, page);// 列,页 
 for(i=0; i<16;i++) 
 {
  LCD_write_byte(hanzi[c*32+i],1); 
 }
 
    LCD_set_XY(row*8, page+1);// 列,页 
 for(i=16; i<32;i++) 
 {
  LCD_write_byte(hanzi[c*32+i],1);
 } 
}
//=================lcd显示函数结束================

//=================18b20相关函数开始==============
/****************DS18B20复位函数************************/
ow_reset(void)
{
char presence=1;
while(presence)
{
  while(presence)
   {
    DQ=1;_nop_();_nop_(); //从高拉倒低
DQ=0;                                       
delay(50);                //550 us
DQ=1;                                        
delay(6);                 //66 us
presence=DQ;              //presence=0 复位成功,继续下一步
   } 
   delay(45);             //延时500 us
   presence=~DQ;         
}
DQ=1;                     //拉高电平
}
//
//
/****************DS18B20写命令函数************************/
void write_byte(uchar val)                //向1-WIRE 总线上写1个字节

[1] [2]  下一页


本文关键字:单片机  程序  显示屏  诺基亚  51单片机单片机-工控设备 - 51单片机