给你改了,对比一下就知道哪里错了。
- #include <reg51.h>
- #include <stdio.h>
- #include <Intrins.h>
- #define pin P0
- sbit RS=P2^2;
- sbit RW=P2^3;
- sbit E=P2^4;
- sbit CS1 = P2^0;
- sbit CS2 = P2^1;
- sbit dat = P2^7;
- unsigned char arr[8]={0,0,0,0,0,0,0,0};
- unsigned char code ch1[]=
- {
- /*-- 文字: 0 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
- /*-- 文字: 1 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,
- /*-- 文字: 2 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
- /*-- 文字: 3 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00,
- /*-- 文字: 4 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24,
- /*-- 文字: 5 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00,
- /*-- 文字: 6 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00,
- /*-- 文字: 7 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00,
- /*-- 文字: 8 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
- /*-- 文字: 9 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00,
- /*-- 文字: . --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,
- /*-- 文字: 温 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,
- 0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,
- /*-- 文字: 度 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,
- 0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,
- /*-- 文字: 湿 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,
- 0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00,
- /*-- 文字: 度 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,
- 0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,
- /*-- 文字: : --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- void wr_command(unsigned char wrcommand) //写指令
- {
- RS=0;
- RW=0;
- E=1;
- pin=wrcommand;
- E=0;
- }
- void wr_data(unsigned char wrdata) //写数据
- {
- RS=1;
- RW=0;
- E=1;
- pin=wrdata;
- E=0;
- }
- void set_page(unsigned char page)//起始页
- {
- page = 0xB8 | page;
- wr_command(page);
- }
- void set_line(unsigned char line)//起始行
- {
- line = 0xC0 | line;
- wr_command(line);
- }
- void set_column(unsigned char column)//起始列
- {
- column = column | 0x40;
- wr_command(column);
- }
- void chose_screen(unsigned char screen) //选择屏幕
- {
- switch(screen)
- {
- case 0:CS1 = 0;CS2 = 0;break;//全
- case 1:CS1 = 0;CS2 = 1;break;//左
- case 2:CS1 = 1;CS2 = 0;break;//右
- default:break;
- }
- }
- void clear_screen(unsigned char screen) //清屏
- {
- unsigned char i,j;
- chose_screen(screen);
- for(i=0;i<8;i++)
- {
- set_page(i);
- set_column(0);
- for(j=0;j<64;j++)
- {
- wr_data(0x00);
- }
- }
- }
- void LCD_init()
- {
- REST=0;
- REST=1;
- chose_screen(0);
- clear_screen(0);
- }
- void show_ch(unsigned char screen,unsigned char page,unsigned char column,unsigned char *p)//显示字符
- {
- unsigned char i;
- chose_screen(screen);
- set_page(page);
- set_column(column);
- for(i=0;i<8;i++)
- {
- wr_data(p[i]); //[/i][i]
- }
- set_page(page+1);
- set_column(column);
- for(i=0;i<8;i++)
- {
- wr_data(p[i+8]);
- }
- }
- void show_ch1(unsigned char screen,unsigned char page,unsigned char column,unsigned char *p)//显示汉字
- {
- unsigned char i;
- chose_screen(screen);
- set_page(page);
- set_column(column);
- for(i=0;i<16;i++)
- {
- wr_data(p[i]); //[/i][i]
- }
- set_page(page+1);
- set_column(column);
- for(i=0;i<16;i++)
- {
- wr_data(p[i+16]);
- }
- }
- void delayus(unsigned char i){
-
- while(i--);
-
- }
- void delayms(unsigned char x)
- {
- unsigned char i, j;
- while(--x){
- _nop_();
- i = 2;
- j = 199;
- do
- {
- while (--j);
- } while (--i);
- }
- }
- void Delay30us() //@11.0592MHz
- {
- unsigned char i;
- i = 11;
- while (--i);
- }
- void dht11_init(){
- //while(1){ //<--------?????? 这里不可以用
- unsigned char high = 0,low = 1;
- dat = 1;
- dat = 0;
- delayms(20);
- dat = 1;
- delayus(6);
- while(!dat);
- while(dat);
- //}
- }
- //读数据的逻辑也不太对,应改为
- unsigned char read_byte(){
- unsigned char byte=0, i;
- for(i=0;i<8;i++){
- while(!dat);
- Delay30us();
- byte<<=1; //<-------------
- if(dat == 1){
- byte = byte | 0x01;
- while(dat);
- }
- }
- return byte;
- }
- unsigned char ste0,ste1,ste2,ste3;
- void dht11_receive(){
- unsigned char byte1,byte2,byte3,byte4,byte5;
- dht11_init();
- byte1 = read_byte();
- byte2 = read_byte();
- byte3 = read_byte();
- byte4 = read_byte();
- byte5 = read_byte();
- dat = 0;
- delayus(7);
- dat = 1;
- if((byte1+byte2+byte3+byte4) == byte5){
- ste0 = byte1;
- ste1 = byte2;
- ste2 = byte3;
- ste3 = byte4;
- }
- }
- void dht11_show(){
- dht11_receive();
- arr[0] = ste0 / 10;//湿度
- arr[1] = ste0 % 10;
- arr[2] = ste1 / 10;
- arr[3] = ste1 % 10;
- arr[4] = ste2 / 10;//温度
- arr[5] = ste2 % 10;
- arr[6] = ste3 / 10;
- show_ch(1,0,0*16,ch1+16*arr[0]);
- show_ch(1,0,1*16,ch1+16*arr[1]);
- //show_ch(1,0,2*16,ch1+16*arr[2]);
- //show_ch(1,0,3*16,ch1+16*arr[3]);
- show_ch(2,32,0*16,ch1+16*arr[4]);
- show_ch(2,32,1*16,ch1+16*arr[5]);
- //show_ch(2,32,2*16,ch1+16*arr[6]);
- }
- void main(){
- char i;
- LCD_init();
- delayms(1000);
- while(1){
- delayms(100);
- //dht11_receive();
- dht11_show();
- }
- }
复制代码
|