⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 温湿度.i

📁 avr基础程序大全
💻 I
字号:
#line 35 "D:\PROGRA~1\AVR\include\AVRdef.h"
unsigned char FlashReadByte(unsigned char ramp, unsigned addr);
unsigned FlashReadWord(unsigned char ramp, unsigned addr);
unsigned long FlashReadLWord(unsigned char ramp, unsigned addr);
void FlashReadBytes(unsigned char ramp, unsigned addr, unsigned char *buf, int n);



unsigned char EDataReadByte(unsigned char ramp, unsigned addr);
unsigned EDataReadWord(unsigned char ramp, unsigned addr);
unsigned long EDataReadLWord(unsigned char ramp, unsigned addr);
void EDataReadBytes(unsigned char ramp, unsigned addr, unsigned char *buf, int n);

void EDataWriteByte(unsigned char ramp, unsigned addr);
void EDataWriteWord(unsigned char ramp, unsigned addr);
void EDataWriteLWord(unsigned char ramp, unsigned addr);
void EDataWriteBytes(unsigned char ramp, unsigned addr, unsigned char *buf, int n);






















void _StackCheck(void);
void _StackOverflowed(char);

#line 14 "E:\AVR自编程序\11avr实验板\21温湿~1\12864.h"
void delay()
{
 asm("nop");
 asm("nop");
}
void delay_us(unsigned int i)
{
 while(i--)
 {;}
}
void delay_ms(unsigned int i)
{
 unsigned int a;
 for(;i;i--)
 {
 for(a=0;a<672;a++);
 }
}
void wr_bit(unsigned char n,unsigned char data)
{
 for(;n;n--) 
 {
 if(data&0x80) 
 {(*(volatile unsigned char *)0x35) |= (1 << (6));}
 else
 {(*(volatile unsigned char *)0x35) &= ~(1 << (6));}
 data=data<<1; 
 delay();
 (*(volatile unsigned char *)0x35) |= (1 << (7)); 
 delay();
 (*(volatile unsigned char *)0x35) &= ~(1 << (7));
 }
}
void write_shuju(unsigned char a,unsigned char b)
{
 (*(volatile unsigned char *)0x35) &= ~(1 << (7));

 wr_bit(5,0xFF); 

 wr_bit(1,0x00); 

 if(a==0) 
 wr_bit(1,0x00); 
 else
 wr_bit(1,0x80); 

 wr_bit(1,0x00); 

 wr_bit(4,b); 

 wr_bit(4,0x00); 

 wr_bit(4,(b<<4)); 

 wr_bit(4,0x00); 

 (*(volatile unsigned char *)0x35) |= (1 << (6)); 
}
void lcd12864_init()
{
 write_shuju(0,0x30); 
 delay_us(200);
 write_shuju(0,0x30); 
 delay_us(80);
 write_shuju(0,0x0C); 
 delay_us(80);
 write_shuju(0,0x40); 
 delay_us(200);
 write_shuju(0,0x01); 
 delay_ms(100);

}
void write_hz(char *s)
 {
 while(*s)
 {
 write_shuju(1,*s);
 s++;
 }
}
void locate(unsigned char x,unsigned char y)
{
 switch(x)
 {
 case 1:write_shuju(0,(0x80+y-1)); break;
 case 2:write_shuju(0,(0x90+y-1));break;
 case 3:write_shuju(0,(0x88+y-1));break; 
 case 4:write_shuju(0,(0x98+y-1));break;
 default:break; 
 }
}
void cls()
{
 delay_us(200);
 write_shuju(0,0x01); 
 delay_ms(20);
}
#line 25 "E:\AVR自编程序\11avr实验板\21温湿~1\温湿度.c"
typedef unsigned char U8; 
typedef signed char S8; 
typedef unsigned int U16; 
typedef signed int S16; 
typedef unsigned long U32; 
typedef signed long S32; 
typedef float F32; 
typedef double F64; 





























 U8 i;
 U8 U8FLAG,k;
 U8 U8count,U8temp;
 U8 U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata;
 U8 U8T_data_H_temp,U8T_data_L_temp,U8RH_data_H_temp,U8RH_data_L_temp,U8checkdata_temp;
 U8 U8comdata;
 U16 ReceiveHighByte;
 U16 ReceiveLowByte;


void port_init(void)
{
 {
 (*(volatile unsigned char *)0x31) = 0xFF; 
 (*(volatile unsigned char *)0x32) = 0x00;
 (*(volatile unsigned char *)0x34) = 0xFF; 
 (*(volatile unsigned char *)0x35) = 0x00; 
 (*(volatile unsigned char *)0x3A) = 0xFE; 
 (*(volatile unsigned char *)0x3B) = 0x00;
 (*(volatile unsigned char *)0x35)|=(1 << (2))+(1 << (5));
 (*(volatile unsigned char *)0x35)&=~(1 << (4));
}

void watchdog_init(void)
{


}


void Delay(unsigned int i)
{
 while(i--);
}

void DelaymS (U16 dly) 
{
 U16 i;
 for ( ; dly>0; dly--)
 {
 asm("wdr");
 for (i=0; i<1119; i++); 
 }
}


 void Delay_10us(void)
 {
 U8 i; 
 i++;i++;i++;i++;i++;i++;i++;i++;i++;
 i++;i++;i++;i++;i++;i++;i++;i++;i++;
 i++;i++;i++;i++;i++;i++;i++;i++;i++;
 i++;i++;i++;i++;i++;i++;i++;i++;i++;
 i++;i++;i++;i++;i++;i++;i++;i++;i++;
 i++;i++;i++;i++;i++;i++;i++;i++;i++;
 i++;i++;i++;i++;i++;i++;i++;i++;i++;
 i++;i++;i++;i++;i++;i++;i++;
 }
 void COM(void)
 {

 U8 i;
 for(i=0;i<8;i++) 
 {

 U8FLAG=2;
 while((!((*(volatile unsigned char *)0x36) & (1 <<4)))&&U8FLAG++);
 if(U8FLAG==1)break;
 Delay_10us();
 Delay_10us();
 Delay_10us();
 Delay_10us();
 U8temp=0;
 if((*(volatile unsigned char *)0x36) & (1 <<4))U8temp=1;
 U8FLAG=2;
 while(((*(volatile unsigned char *)0x36) & (1 <<4))&&U8FLAG++);

 if(U8FLAG==1)break;




 U8comdata<<=1;
 U8comdata|=U8temp; 
 } 

 }














 void RH(void)
 {


 (*(volatile unsigned char *)0x37) |= (1 << 4);
 (*(volatile unsigned char *)0x38) &= ~(1 << 4);
 DelaymS(1);
 (*(volatile unsigned char *)0x37) &= ~(1 << 4);
 (*(volatile unsigned char *)0x38) |= (1 << 4);


 Delay_10us();
 Delay_10us();
 Delay_10us();
 Delay_10us();





 if((*(volatile unsigned char *)0x36) & (1 <<4))U8FLAG=1;
 while(!((*(volatile unsigned char *)0x36) & (1 <<4))) 
 {
 U8FLAG=2;


 while((!((*(volatile unsigned char *)0x36) & (1 <<4)))&&U8FLAG++);
 if(U8FLAG==1)break;
 U8FLAG=2;


 while(((*(volatile unsigned char *)0x36) & (1 <<4))&&U8FLAG++);
 if(U8FLAG==1)break;

 COM();
 if(U8FLAG==1)break;
 U8T_data_H_temp=U8comdata;
 COM();
 if(U8FLAG==1)break;
 U8T_data_L_temp=U8comdata; 
 COM();
 if(U8FLAG==1)break;
 U8RH_data_H_temp=U8comdata;
 COM();
 if(U8FLAG==1)break;
 U8RH_data_L_temp=U8comdata;
 COM();
 if(U8FLAG==1)break;
 U8checkdata_temp=U8comdata;
 break;
 } 

 (*(volatile unsigned char *)0x37) &= ~(1 << 4);
 (*(volatile unsigned char *)0x38) |= (1 << 4);


 U8temp=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_data_L_temp);
 if(U8temp==U8checkdata_temp)
 {
 U8RH_data_H=U8T_data_H_temp;
 U8RH_data_L=U8T_data_L_temp;
 U8T_data_H=U8RH_data_H_temp;
 U8T_data_L=U8RH_data_L_temp;
 U8checkdata=U8checkdata_temp;
 } 


 (*(volatile unsigned char *)0x37) &= ~(1 << 4);
 (*(volatile unsigned char *)0x38) |= (1 << 4);

 }











































void init_devices(void) 
{
unsigned char i;
 asm("cli"); 
 port_init();







} 












 void main(void)
{

 init_devices() ;
 (*(volatile unsigned char *)0x37) &= ~(1 << 4);
 (*(volatile unsigned char *)0x38) |= (1 << 4);

 while(1)
 {


 RH();











 lcd12864_init();
 cls(); 
 delay_ms(2);
 locate(1,3);write_hz("滨州学院");
 locate(2,1);write_hz("创新实验室  OK"); 


 locate(3,1);write_hz("ATmega16 ADC学习"); 
 write_shuju(1,U8RH_data_H);
 write_shuju(1,U8RH_data_L);
 write_shuju(1,U8T_data_H);
 write_shuju(1,U8T_data_L);
 write_shuju(1,U8checkdata);



 for(U8temp=0;U8temp<200;U8temp++)
 {
 DelaymS(10);

 } 

 }

}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -