1、/需要找元器件的符号/*LCD1602 相关程序*/#define uchar unsigned char#define uint unsigned int/LCD1602 端口定义sbit RS=P20;sbit RW=P21;sbit E=P22;void delay(uchar x) /延时uchar y;while(x-)for(y=0;y=1;DQ=1;if(DQ) n|=0x80;delay1(10);return n;void write_byte(uchar k)/写字节uchar i;for(i=0;i=1;void read_temp() /读取温度Init_DS18B20
2、();write_byte(0xcc);write_byte(0xbe);temp0=read_byte();temp1=read_byte(); Init_DS18B20();write_byte(0xcc);write_byte(0x44);delay1(10);/*/温度显示*void display()uchar aa,cc,k,i=0;k=temp_value1 /与以后是否为负数if(k=0xf8) /假如为负数temp_value1=temp_value1; /高位取反temp_value0=temp_value0+1; /低位取反加 1DSY_CODE27=-; /显示负号if
3、(temp_value0=0)temp_value1=temp_value1+1; / 低位为 0 时高位取反加1else DSY_CODE27= ;cc=(temp_value04)|(temp_value1)#include #include#define uint unsigned int#define uchar unsigned charuchar SN88=0x28,0x30,0xc5,0xb8,0x00,0x00,0x00,0x8e,0x28,0x31,0xc5,0xb8,0x00,0x00,0x00,0xb9,0x28,0x32,0xc5,0xb8,0x00,0x00,0x00
4、,0xe0,0x28,0x33,0xc5,0xb8,0x00,0x00,0x00,0xd7,0x28,0x34,0xc5,0xb8,0x00,0x00,0x00,0x52,0x28,0x35,0xc5,0xb8,0x00,0x00,0x00,0x65,0x28,0x36,0xc5,0xb8,0x00,0x00,0x00,0x3c,0x28,0x37,0xc5,0xb8,0x00,0x00,0x00,0x0b;uchar code DSY_CODE1=“Current Temp : “;uchar DSY_CODE2=“TEMP: “;sbit DQ=P10;uchar temp_value=0
5、x00,0x00;uchar disbuffer=0,0,0;uchar num;void delay1(uchar n)/n=1 时大概延时 6.9uswhile(n-);uchar ow_DS18B20()/DS18B20 复位uchar m;DQ=0;delay1(100);DQ=1;delay1(4);m=DQ;delay1(40);return m;uchar read_byte()/读取字节uchar i;uchar n=0;for(i=0;i=1;DQ=1;if(DQ)n|=0x80;delay1(10);return(n);void write_byte(uchar k)/写字
6、节uchar i;for(i=0;i=1;void read_temp()/读温度uchar i,j;uchar aa,cc,k;write_byte(0xcc);write_byte(0x44);for(j=0;j4)|(temp_value1)=1;uchar read_byte()/读取一字节uchar i,b=0x00;for(i=0;i40x0f;switch(b) /先去确定列case 1: c=c+0;break; /第一行case 2: c=c+4;break;case 4: c=c+8;break;case 8: c=c+12;/*LCD12864 相关程序*/#define
7、 uchar unsigned char#define uint unsigned int#define disp_Off 0x3e /关显示#define disp_On 0x3f / 开显示#define Page_Add 0xb8 /页地址#define Col_Add 0x40 /列地址#define Start_Line 0xc0 /行地址sbit RS= P20;sbit RW= P21;sbit E = P22;sbit CS1=P23;sbit CS2=P24;sbit RST=P25;uchar code wenzi32; /文字字模的定义uchar code shuzi16
8、; /数字字摸的定义bit LCD_busy() / 检查忙位P0=0xff;RST=1;RW=1;RS=0;E=1;E=0;return (bit)(P0void LCD_write_com(uchar com) /写命令到 LCDLCD_busy();RW=0;RS=0;E=0;P0=com;E=1;E=0;void LCD_write_data(uchar date)/ 写数据到 LCDLCD_busy();RW=0;RS=1;P0=date;E=1;E=0;void LCD_Reset() / 初始化 LCD 屏 CS1=1;CS2=1;LCD_write_com(0x38);LCD_
9、write_com(0x0f); LCD_write_com(0x01);LCD_write_com(0x06); LCD_write_com(Start_Line); void CLR_12864() /清屏uchar j,k;CS1=0;CS2=0;LCD_write_com(Page_Add+0);LCD_write_com(Col_Add+0);for(k=0;k8;k+)LCD_write_com(Page_Add+k);for(j=0;j64;j+)LCD_write_com(Col_Add+j);LCD_write_data(0x00);void display_a_char(u
10、char p,uchar l,uchar n) /显示数字 8*16 的数字 /第 P 行第 L 位显示Muchar i,j;for(j=0;j2;j+)LCD_write_com(Page_Add+p+j);LCD_write_com(Col_Add+l);for(i=0;i8;i+) LCD_write_data(shuzin8*j+i); /shuzi 为需要的数字void display_a_word(uchar p,uchar l,uchar n) /显示数字 16*16 的汉字uchar i,j;for(j=0;j2;j+)LCD_write_com(Page_Add+p+j);L
11、CD_write_com(Col_Add+l);for(i=0;i16;i+) LCD_write_data(wenzin16*j+i); /wenzi 为需要的数字void disp_img(uchar code *img) /显示 12864 图片 不需图片时可以不要uchar j,k;for(k=0;k8;k+)CS2=1; CS1=0;LCD_write_com(Page_Add+k);LCD_write_com(Col_Add+0);for(j=0;j64;j+) LCD_write_data(imgk*128+j);CS2=0; CS1=1;LCD_write_com(Page_A
12、dd+k);LCD_write_com(Col_Add+0);for(j=64;j128;j+) LCD_write_data(imgk*128+j);*/*12864 显示*/void display(void) /12864 上显示所需的字符 CLR_12864();CS1=0;CS2=1;display_a_word(0,16,0); /床 :从显示屏的第二个开始显示 /可以是 display_a_word(0,0,0)从第一个显示;display_a_word(0,32,1); /前display_a_word(0,48,2); /明CS1=1;CS2=0;display_a_word
13、(0,0,3); /月display_a_word(0,16,4); /光display_a_word(0,32,20); /,CS1=0;CS2=1;display_a_word(2,16,5); /疑display_a_word(2,32,6); /似display_a_word(2,48,7); /地CS1=1;CS2=0;display_a_word(2,0,8); /上display_a_word(2,16,9); /霜display_a_word(2,32,21); /。CS1=0;CS2=1;display_a_word(4,16,10); /举display_a_word(4,
14、32,11); /头display_a_word(4,48,12); /望CS1=1;CS2=0;display_a_word(4,0,13); /明display_a_word(4,16,14); /月display_a_word(4,32,20); /,CS1=0;CS2=1;display_a_word(6,16,15); /低display_a_word(6,32,16); /头display_a_word(6,48,17); /思 CS1=1;CS2=0;display_a_word(6,0,18); /故display_a_word(6,16,19); / 乡display_a_w
15、ord(6,32,21); /。void main()LCD_Reset();/复位 CLR_12864();/清屏 display(); /显示 disp_img(FirstPage);/显示图片可以不要 FirstPage 指的是图片的字模while(1); /unsigned char code FirstPage=;/*电机相关程序(步进机)*/#define uchar unsigned char#define uint unsigned intuchar code FFW=0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09;uchar code REV=0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01;void STEP_FFW()/电机正转uchar i,j;for(i=0;i5;i+)for(j=0;j8;j+)P3=FFWj*0.1;delay(25);void STEP_REV()uchar i,j;for(i=0;i5;i+)for(j=0;j8;j+)P3=REVj;delay(25);