单片机大屏幕双热电偶仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
CONN-DIL36
单片机源程序如下:
- #include "reg51.h"
- #include "intrins.h"
- typedef unsigned char uint8;
- typedef unsigned int uint16;
- typedef unsigned long uint32;
- bit flag;
- sbit MAX_SO=P1^0;
- sbit MAX_SCK=P1^1;
- sbit MAX_CS1=P1^2;
- sbit MAX_CS2=P1^3;
- int dat1;
- #define LCD_CUR_POS 0x21 /* 光标位置设置(只有设置到有效显示地址并打开显示时才看到) */
- #define LCD_CGR_POS 0x22 /* CGRAM偏置地址设置(可以增加自已的符号) */
- #define LCD_ADR_POS 0x24 /* 地址指针位置(设置读写操作指针) */
- #define LCD_TXT_STP 0x40 /* 文本区首址(从此地址开始向屏幕左上角显示字符) */
- #define LCD_TXT_WID 0x41 /* 文本区宽度(设置显示宽度,N/6或N/8,其中N为x轴的点数) */
- #define LCD_GRH_STP 0x42 /* 图形区首址(从此地址开始向屏幕左上角显示点) */
- #define LCD_GRH_WID 0x43 /* 图形区宽度(设置显示宽度,N/6或N/8,其中N为x轴的点数) */
- #define LCD_MOD_OR 0x80 /* 显示方式:逻辑或 */
- #define LCD_MOD_XOR 0x81 /* 显示方式:逻辑异或 */
- #define LCD_MOD_AND 0x82 /* 显示方式:逻辑与 */
- #define LCD_MOD_TCH 0x83 /* 显示方式:文本特征 */
- #define LCD_DIS_SW 0x90 /* 显示开关:D0=1/0,光标闪烁启用/禁用 */
- /* D1=1/0,光标显示启用/禁用 */
- /* D2=1/0,文本显示启用/禁用(打开后再使用) */
- /* D3=1/0,图形显示启用/禁用(打开后再使用) */
-
- #define LCD_CUR_SHP 0xA0 /* 光标形状选择:0xA0-0xA7表示光标占的行数 */
- #define LCD_AUT_WR 0xB0 /* 自动写设置 */
- #define LCD_AUT_RD 0xB1 /* 自动读设置 */
- #define LCD_AUT_OVR 0xB2 /* 自动读/写结束 */
- #define LCD_INC_WR 0xC0 /* 数据一次写,地址加1 */
- #define LCD_INC_RD 0xC1 /* 数据一次读,地址加1 */
- #define LCD_DEC_WR 0xC2 /* 数据一次写,地址减1 */
- #define LCD_DEC_RD 0xC3 /* 数据一次读,地址减1 */
- #define LCD_NOC_WR 0xC4 /* 数据一次写,地址不变 */
- #define LCD_NOC_RD 0xC5 /* 数据一次读,地址不变 */
- #define LCD_SCN_RD 0xE0 /* 屏读 */
- #define LCD_SCN_CP 0xE8 /* 屏拷贝 */
- #define LCD_BIT_OP 0xF0 /* 位操作:D0-D2--定义D0-D7位,D3--1为置位,0为清除 */
- uint8 const code BMP[]=
- {
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- …………
- …………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x31,0x80,0x61,0x80,0x60,0xC0,0x60,0xC0,0x60,0xC0,0x31,0xC0,0x1F,0xC0,0x00,0xC0,0x01,0x80,0x61,0x80,0x63,0x00,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"9",9*/
- };
- uint8 xdata LCD_Command _at_ 0xfdff;
- uint8 xdata LCD_Data _at_ 0xfcff;
- void LCD_Write_Command(uint8 dat)
- {
- while(!(0xfe|LCD_Command));
- LCD_Command=dat;
- }
- void LCD_Write_Data(uint8 dat)
- {
- while(!(0xfd|LCD_Command));
- LCD_Data=dat;
- }
- #define LCD_Read_Command() LCD_Command
- #define LCD_Read_Data() LCD_Data
- void LCD_Write_Command3(uint8 command,uint8 dat1,uint8 dat2)
- {
- LCD_Write_Data(dat1);
- LCD_Write_Data(dat2);
- LCD_Write_Command(command);
- }
- void LCD_Write_Command1(uint8 command,uint8 dat1)
- {
- LCD_Write_Data(dat1);
- LCD_Write_Command(command);
- }
- void LCD_Initialize()
- {
- LCD_Write_Command3(LCD_TXT_STP,0x00,0x00);
- LCD_Write_Command3(LCD_TXT_WID,32,0x00);
- LCD_Write_Command3(LCD_GRH_STP,0x00,0x00);
- LCD_Write_Command3(LCD_GRH_WID,32,0x00);
- LCD_Write_Command(LCD_MOD_OR);
- LCD_Write_Command(LCD_DIS_SW|0x08);
- }
- void LCD_FillAll(uint8 dat)
- { uint32 i;
- LCD_Write_Command3(LCD_ADR_POS, 0x00, 0x00); // 置地址指针
- LCD_Write_Command(LCD_AUT_WR); // 自动写
- for(i=0;i<240*128;i++)
- {
- LCD_Write_Data(dat);
- }
- LCD_Write_Command(LCD_AUT_OVR); // 自动写结束
- LCD_Write_Command3(LCD_ADR_POS,0x00,0x00); // 重置地址指针
- }
- void LCD_UpdatePoint(uint32 x, uint32 y,uint8 dat)
- { uint32 addr;
-
- /* 找出目标地址 */
- addr = y*(256>>3) + (x>>3);
- LCD_Write_Command3(LCD_ADR_POS, addr&0xFF, addr>>8); // 置地址指针
-
- /* 输出数据 */
- LCD_Write_Command1(LCD_INC_WR, dat);
- }
- void Disp_LCD_HZ(uint16 x,uint16 y,uint16 xsize,uint16 ysize,uint8 *dat)
- {
- uint32 i,j;
- for(j=0;j<ysize;j++)
- {
- for(i=0;i<xsize;)
- {
- LCD_UpdatePoint(i+x,j+y,*dat);
- dat++;
- i+=8;
- }
- }
- }
- void Disp_LCD(uint8 *dat)
- {
- uint32 i,j;
- for(j=0;j<255;j++)
- {
- for(i=0;i<255;)
- {
- LCD_UpdatePoint(i,j,*dat);
- dat++;
- i+=8;
- }
- }
- }
- void Delay()
- {
- uint32 i,j;
- for(i=0;i<512;i++)
- for(j=0;j<22;j++);
- }
- void MAX_Init()
- {
- MAX_SCK=0;
- MAX_SCK=0;
- MAX_CS1=0;
- MAX_CS2=0;
- MAX_CS1=1;
- MAX_CS2=1;
- MAX_SO=1;
- }
- int MAX_Read_Temp()
- {
- static char i;
- static int temp=0;
- for(i=0;i<16;i++)
- {
- temp|=MAX_SO;
- temp<<=1;
- MAX_SCK=1;
- _nop_();
- MAX_SCK=0;
- }
- if(temp&0x04)flag=1;
- else flag=0;
- MAX_CS1=1;
- MAX_CS2=1;
- return temp>>3;
- }
- void Disp_Temp(uint8 type)
- {
- int dat;
- if(type==2){MAX_CS1=0;MAX_CS2=1;}
- else
- {MAX_CS1=1;MAX_CS2=0;}
- dat=MAX_Read_Temp();
- dat*=10;
- dat/=4;
- dat1=dat;
- // if(flag){
- // print(0," ERROR TEMP");
- // print(0x40," ");
- // }
- // else
- // {
- // print(5," ");
- // print(0,temp_value);
- // print(0x40,"TEMP OUT ");
- // }
- }
-
- void main()
- {
- uint8 i;
- LCD_Initialize();
- MAX_CS1=0;MAX_CS2=0;
- MAX_Init();
- Disp_LCD(BMP);
- for(i=0;i<9*15;i++)
- {
- Disp_LCD_HZ(64+i,204,14,12,INIT);
- Delay();
- i+=15;
- }
- Disp_LCD(BMP1);
- Disp_LCD_HZ(0,0,20,20,HZK[0]);
- Disp_LCD_HZ(22,0,20,20,HZK[1]);
- Disp_LCD_HZ(2*22,0,20,20,HZK[2]);
- Disp_LCD_HZ(3*22,0,20,20,HZK[3]);
- Disp_LCD_HZ(4*22,0,20,20,HZK[4]);
- Disp_LCD_HZ(5*22,0,20,20,HZK[5]);
-
- Disp_LCD_HZ(0,22,20,20,HZK[7]);
- Disp_LCD_HZ(22,22,20,20,HZK[1]);
- Disp_LCD_HZ(2*22,22,20,20,HZK[2]);
- Disp_LCD_HZ(3*22,22,20,20,HZK[3]);
- Disp_LCD_HZ(4*22,22,20,20,HZK[4]);
- Disp_LCD_HZ(5*22,22,20,20,HZK[5]);
- while(1)
- {
- Disp_Temp(1);
- if(flag)
- {
- Disp_LCD_HZ(6*22,0,20,20,HZK[8]);
- Disp_LCD_HZ(7*22,0,20,20,HZK[9]);
- }
- else
- {
- Disp_LCD_HZ(7*22+22,0,20,20,HZK[6]);
- Disp_LCD_HZ(6*22+20,0,10,20,NUM[((dat1/10)%10)]);
- Disp_LCD_HZ(6*22+10,0,10,20,NUM[((dat1/100)%10)]);
- Disp_LCD_HZ(6*20,0,10,20,NUM[((dat1/1000)%10)]);
- }
- Disp_Temp(2);
- if(flag)
- {
- Disp_LCD_HZ(6*22,22,20,20,HZK[8]);
- Disp_LCD_HZ(7*22,22,20,20,HZK[9]);
- }
- else
- {
- Disp_LCD_HZ(7*22+22,22,20,20,HZK[6]);
- Disp_LCD_HZ(6*22+20,20,10,20,NUM[((dat1/10)%10)]);
- Disp_LCD_HZ(6*22+10,20,10,20,NUM[((dat1/100)%10)]);
- Disp_LCD_HZ(6*20,20,10,20,NUM[((dat1/1000)%10)]);
- }
-
- // else
- // print(0,temp_value);
- // Disp_Temp(2);
- // if(flag)print(0x40,"NOP ");
- // else
- // print(0x40,temp_value);
- }
- }
复制代码
所有资料51hei提供下载:
temp.rar
(190.82 KB, 下载次数: 32)
|