智能车制作
标题:
大家看一下我的5110程序,怎么显示不了。谢谢了。我的是K60的,接线没有问题。
[打印本页]
作者:
爱的港湾
时间:
2013-5-24 19:32
标题:
大家看一下我的5110程序,怎么显示不了。谢谢了。我的是K60的,接线没有问题。
#include "include.h"
#define uchar unsigned char
#define uint unsigned int
//位操作定义
#define SCLK PTB21_OUT
#define SDIN PTB22_OUT
#define LCD_DC PTC7_OUT
#define LCD_CE PTC6_OUT
#define LCD_RST PTC15_OUT
typedef struct typHZ_GB12 /*12*12 汉字字模显示数据结构,一个汉字分为上下两层*/
{
char Index[2];//一个汉字占两个字节
char Msk[24];//一个汉字的编码由 24 个十六进制数组成
};
struct typHZ_GB12 const GB_12[] ={
{0xEF,0x09,0xF9,0x4F,0x40,0xFF,0x49,0x49,0x49,0x79,0x01,0x00,0x07,0x04,0x03,0x02,0x02,0x07,0x04,0x04,0x04,0x04,0x04,0x00},
{0x02,0x82,0xBE,0xA2,0xB6,0xEB,0xB6,0xA2,0xBE,0x82,0x02,0x00,0x00,0x07,0x00,0x02,0x03,0x02,0x02,0x03,0x04,0x07,0x00,0x00},
{0x89,0x72,0x00,0xC0,0x5F,0xD5,0x55,0xD5,0x55,0xDF,0x00,0x00,0x07,0x00,0x04,0x07,0x04,0x07,0x04,0x07,0x04,0x07,0x04,0x00},
{0x00,0xFE,0x0A,0x8A,0xBE,0xAA,0xAB,0xAA,0xBE,0x0A,0x0A,0x00,0x06,0x01,0x04,0x04,0x04,0x03,0x02,0x03,0x04,0x04,0x04,0x00},
{0x10,0x08,0xFC,0xAB,0xAA,0xFA,0xAE,0xAA,0xA8,0xF8,0x00,0x00,0x04,0x02,0x01,0x00,0x00,0x07,0x00,0x04,0x04,0x07,0x00,0x00},
{0x00,0xFE,0x0A,0x8A,0xBE,0xAA,0xAB,0xAA,0xBE,0x0A,0x0A,0x00,0x06,0x01,0x04,0x04,0x04,0x03,0x02,0x03,0x04,0x04,0x04,0x00}
};
unsigned char font6x8[][6] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
{ 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
{ 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g
{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j
{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p
{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines
};
/***********************************************************************
* 函数名称:delay_us()
* 函数功能:延时t 微秒
* 入口参数:t 延时 t 微秒
* 出口参数:无
***********************************************************************/
void delay_us(void) //1.28us延时函数
{
volatile u16 i;
for(i=0;i<30;i++) ;
}
/**********************************************************************
* 函数名称:LCD_init()
* 函数功能:初始化 nokia5110
* 入口参数:无
* 出口参数:无
**********************************************************************/
void LCD_init(void)
{
LCD_RST = 0; // 产生一个让 LCD 复位的低电平脉冲
delay_us();
LCD_RST = 1;
LCD_CE = 0;// 关闭 LCD
delay_us();
LCD_CE = 1;// 使能 LCD
delay_us(); delay_us();
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); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示
LCD_CE = 0; // 关闭 LCD
}
/**********************************************************************
* 函数名称:LCD_clear()
* 函数功能:液晶清屏
* 入口参数:无
* 出口参数:无
**********************************************************************/
void LCD_clear(void)
{
uint i;
LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);
for (i=0; i<504; i++)
LCD_write_byte(0, 1);
}
/**********************************************************************
* 函数名称:LCD_set_XY()
* 函数功能:光标定位x 行 列
* 入口参数:X,Y x 行 列
* 出口参数:无
**********************************************************************/
void LCD_set_XY(uchar X, uchar Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}
/***********************************************************************
* 函数名称:LCD_write_char()
* 函数功能:写入 1 个字符
* 入口参数:c 要写入的数据
* 出口参数:无
**********************************************************************/
void LCD_write_char(uchar c)
{
uchar line;
c -= 32;
for (line=0; line<6; line++)
LCD_write_byte(font6x8[c][line], 1);//从 ACSII 码表中读取字节,然后写入液晶
}
/***********************************************************************
* 函数名称? LCD_write_english_string()
* 函数功能:写英文字符串
* 入口参数:X,Y,*S------x 行 列*s 为英文字符串
* 出口参数:无
***********************************************************************/
void LCD_write_english_string(uchar X,uchar Y,char *s)
{
LCD_set_XY(X,Y);//光标定位
while (*s)
{
LCD_write_char(*s);
s++;
}
}
/**********************************************************************
* 函数名称:LCD_write_byte()
* 函数功能:写一个字节
* 入口参数:dat,要写入的字节;command:0 为命令,1 为数据
* 出口参数:无
***********************************************************************/
void LCD_write_byte(uchar dat, uchar command)
{
uchar i;
LCD_CE = 0;
if (command == 0)
LCD_DC = 0;
else
LCD_DC = 1;
for(i=0;i<8;i++)
{
if(dat&0x80)
SDIN = 1;
else
SDIN = 0;
SCLK = 0;
dat = dat << 1;
SCLK = 1;
}
LCD_CE = 1;
}
/**********************************************************************
* 函数名称:LCD_write_chinesee()
* 函数功能:写一个汉字
* 入口参数:x,横坐标;y,纵坐标;hz,要显示的汉字
* 出口参数:无
**********************************************************************/
void LCD_write_chinese(unsigned char x, unsigned char y, unsigned char *hz)
{
unsigned char k,i;
for(k=0;k<sizeof(GB_12)/sizeof(GB_12[0]);k++)//查找汉字编码表中的汉字
{
if(hz[0] == GB_12[k].Index[0] && hz[1] == GB_12[k].Index[1])
break;
}
LCD_set_XY(x,y); //光标定位
for(i=0;i<12;i++)//先写上半字节
LCD_write_byte(GB_12[k].Msk[i],1);
LCD_set_XY(x,y+1);//光标定位下一行
for(i=12;i<24;i++)//后写下半字节
LCD_write_byte(GB_12[k].Msk[i],1);
}
/***********************************************************************
* 函数名称: LCD_write_chinese_sring()
* 函数功能:写汉字串
* 入口参数:x,横坐标;y,纵坐标;string,要显示的汉字串
* 出口参数:无
***********************************************************************/
void LCD_write_chinese_sring(unsigned char x, unsigned char y,unsigned char *string)
{
unsigned char i=0,j=0,k=0;
while(string[i])
{
LCD_write_chinese(x,y,&string[i]);
x=x+12;
i=i+2;
}
}
void main()
{
u16 i;
DisableInterrupts; //禁止总中断
uart_init (UART1 ,19200);
//gpio_init(PORTC,7,GPO,1);
//gpio_init(PORTC,6,GPO,1);
//gpio_init(PORTB,22,GPO,1);
//gpio_init(PORTB,21,GPO,1);
DDRC6=0;DDRC7=0;DDRB22=0;DDRB21=0;
PTC7_OUT=0
TC6_OUT=0;PTB22_OUT=0;PTB21_OUT=0;
//GPIO_SET(PORTC,7,1);GPIO_SET(PORTC,6,1);GPIO_SET(PORTB,22,1);GPIO_SET(PORTB,21,1);
LCD_init(); //初始化液晶
LCD_clear();
EnableInterrupts;
LCD_set_XY(0, 0);
LCD_write_chinese_sring(0,0,"距离");
LCD_write_english_string(72,0,"CM");
while(1)
{
}
}
作者:
爱的港湾
时间:
2013-5-24 19:33
额,明明是程序,怎么会成为表情。
作者:
bloong
时间:
2013-5-24 20:19
建议用oled屏吧 做车的话
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2