智能车制作

标题: 单片机超频80Mhz,在诺基亚lcd5110上显示汉字和数字。 [打印本页]

作者: 醉清风    时间: 2011-10-30 17:17
标题: 单片机超频80Mhz,在诺基亚lcd5110上显示汉字和数字。
一段程序,总体是有错误,提示不识别sbit。头都大了…

#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
#define uchar unsigned char
#define uint unsigned int


void delay_1ms(void);
void delay(uint );
void LCD_write_byte(unsigned char, unsigned char);
void LCD_init(void);
void LCD_set_XY(unsigned char, unsigned char);
void LCD_clear(void);
void LCD_write_char(unsigned char);
void LCD_write_hanzi(unsigned char, unsigned char,unsigned char);

//PB 口
sbit    sce PORTB_PB0           //片选   
sbit   res PORTB_PB1        //复位,0复位
sbit    dc  PORTB_PB2       //1写数据,0写指令
sbit    sdin PORTB_PB5         //数据
sbit    sclk PORTB_PB7        //时钟

void main(void)
{
  /* put your own code here */

unsigned char k;
res=0;
for(k=0;k<250;k++);
res=1;     
LCD_init();                            //初始化LCD模块
LCD_clear();                           // 清屏幕

LCD_write_hanzi(1,0,0);               
LCD_write_hanzi(3,0,1);               
LCD_write_hanzi(5,0,2);               
LCD_write_hanzi(7,0,3);              

LCD_write_hanzi(1,2,4);              
LCD_write_hanzi(4,2,5);               
LCD_write_hanzi(7,2,6);                 

     
LCD_write_char(33);  
LCD_write_char(34);   
LCD_write_char(35);  
LCD_write_char(36);   
LCD_write_char(37);  
LCD_write_char(38);   
LCD_write_char(39);   
LCD_write_char(40);   
LCD_write_char(41);   
LCD_write_char(1);   
   while(1)
      {
      }  
      
}


void delay_1ms(void)              //  1 ms延时
{
unsigned int i;
for (i=0;i<500;i++);
}

void delay(uint t)                   //延时 t ms
{
for (;t>0;t--)
delay_1ms();

}


void LCD_write_byte(uchar dt, uchar command)      //lcd显示函数开始     使用SPI接口写数据到LCD
{
uchar i;
                                
sce=0;                                   //片选有效,允许输入数据
dc=command;                             //模式选择 0,写命令;1.写数据
for(i=0;i<8;i++)                        //传送8位数据
{
   if(dt&0x80)
   sdin=1;  
   else
   sdin=0;
   sclk=0;
   dt=dt<<1;  
   sclk=1;
}
dc=1;                                     //写数据
sce=1;                                    //禁止5110
sdin=1;
}


void LCD_init(void)        //5110LCD初始化
{

res=0;   
delay_1ms();
res=1;   
sce=0;
delay_1ms();
sce=1;
delay_1ms();

LCD_write_byte(0x21,0);//初始化Lcd,功能设定使用扩充指令
LCD_write_byte(0xc8,0);//设定液晶偏置电压
LCD_write_byte(0x06,0);//温度校正
LCD_write_byte(0x13,0);//1:48
LCD_write_byte(0x20,0);//使用基本指令 V=0,水平寻址
LCD_clear();;          //清屏
LCD_write_byte(0x0C,0);//设定显示模式,正常显示
sce=0;                  //关闭LCD
}


void LCD_set_XY(uchar X, uchar Y)           //  设置LCD坐标函数 输入参数:x:0-83 y:0-5
{
LCD_write_byte(0x40 | Y, 0);// column
LCD_write_byte(0x80 | X, 0);// row
}


void LCD_clear(void)   //LCD清屏函数
{
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);   
   }
}
}


void LCD_write_char(uchar c)            //显示英文字符
{
unsigned char line;
c-=32;                                    //数组的行号   
                                    
for(line=0;line<6;line++)  
LCD_write_byte(font6*8[c][line],1);      
}  


void LCD_write_hanzi(uchar row, uchar page,uchar c)           //输出汉字
{
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);
}
}
作者: lrbdh    时间: 2011-10-31 07:02
关注ing......




欢迎光临 智能车制作 (http://111.231.132.190/) Powered by Discuz! X3.2