Beispiel #1
0
uchar nRF24L01_RxPacket(uchar *rx_buf)
{	 
    uchar revale=0;
	SPI_Write_Buf(WRITE_REG + RX_ADDR_P0,RX_ADDRESS, RX_ADR_WIDTH);
	CE=0;
	SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f);   		// IRQ收发完成中断响应,16位CRC	,主接收
	CE = 1; 
	inerDelay_us(130);
	sta=SPI_Read(STATUS);     // 读取状态寄存其来判断数据接收状况
	if(RX_DR)				// 判断是否接收到数据
	{
	    CE = 0; 			//SPI使能
		SPI_Read_Buf(RD_RX_PLOAD,rx_buf,RX_PLOAD_WIDTH);// read receive payload from RX_FIFO buffer
		revale =1;			//读取数据完成标志
						write_com(0x80);
						write_str("   Hum");
						write_data(':');
						write_data(rx_buf[1]/10%10+48);
						write_data(rx_buf[1]%10+48);
						
						write_data('%');
						write_com(0x80+0x40);
						write_str("   Tem");
						write_data(':');
						write_data(rx_buf[2]/10%10+48);
						write_data(rx_buf[2]%10+48);
                        write_data(0xdf);
						write_data('c');
				
	}
	SPI_RW_Reg(WRITE_REG+STATUS,sta);   //接收到数据后RX_DR,TX_DS,MAX_PT都置高为1,通过写1来清楚中断标志
	return revale;
}
Beispiel #2
0
void init_1602()
{
   write_com(0x38);
   write_com(0x0c);
   write_com(0x06);
   write_com(0x01);
}
Beispiel #3
0
void moveto(unsigned char row,unsigned char line)
{
	if(row==1)
		write_com(0x80+line);
	if(row==2)
		write_com(0x80+0x40+line);
}
Beispiel #4
0
void display(unsigned char *temp)
{
	char n;
//	sprintf(buf,"%.3f\0",date);
	n=strlen(temp);
	i=n;
	if(n<=0)
	{
		clear(2);
		write_com(0x01);
		write_com(0x80+0x40+14);
		write_data('0');
		write_data('.');
	}
	else
	{
/*		while(temp[i-2]!='0')
		{
			temp[i-1]='\0';
			i--;
		}*/
		if(n>16) n=16;
		clear(2);
		write_com(0x80+0x40+16-n);
		for(i=0;i<16;i++)
		write_data(temp[i]);
	}
}
Beispiel #5
0
void main()
{
	init_ds1302();
	init_12232();
	write_com(0x81);
	write_data(table1[0]);
	write_data(table1[1]);
	write_com(0x83);
	write_data(table1[2]);
	write_data(table1[3]);
	write_com(0x85);
	write_data(table1[4]);
	write_data(table1[5]);
	write_com(0x92);
	write_data(table1[6]);
	write_com(0x94);
	write_data(table1[6]);
	gettime();
	secondold=readsecond; 
	while(1)
	{
		second=readsecond;
		delay(100);
		if(second!=secondold&&second<60) 
		{
			displaytwo(15,second); secondold=second;
			if(second==0)
			{
				gettime();
			}
		}	  
	}
}
Beispiel #6
0
void main()
{
	while(1) 
	{
		unsigned int pos=0;
		init();
		write_com(0x80+0x10);//光标位置在右侧外
		for(num=0;num<strlen(line1);num++)//strlen来计算字符串长度
		{
			write_data(line1[num]);
			delay_ms(5);
		}
		write_com(0x80+0x50);//光标位置调整到第二行右侧外
		for(num=0;num<strlen(line2);num++)
		{
			write_data(line2[num]);
			delay_ms(5);
		}
		while(pos!=16+MAX(strlen(line1),strlen(line2)))
		{	
			if (pos==(16+MAX(strlen(line1),strlen(line2)))/2)//在中间暂停1s
			{
				delay_ms(1000);
			}
			write_com(0x18);//屏幕左移
			delay_ms(200);
			pos++;
		}
	}
	
	
}
Beispiel #7
0
void LCD1602_init()	    //1602初始化
{
	lcden=0;
	write_com(0x38);	//设置16*2显示,5*7点阵,8位数据接口
	write_com(0x0c);	//设置开显示,不显示光标
	write_com(0x06);	//写一个字符后地址指针加1
	write_com(0x01);	//清0操作

}
 void init1602(){	   //1602液晶初始化设定
	 lcdrw=0;
	 lcden=0;
	 write_com(0x3c);
	 write_com(0x0c);
	 write_com(0x06);
	 write_com(0x01);
	 write_com(0x80);
}
Beispiel #9
0
void init()			 //初始化
{
   dula=0;wela=0;
   en=0;
   write_com(0x38);
   write_com(0x0c);
   write_com(0x06);
   write_com(0x80);
   write_com(0x01);
}
Beispiel #10
0
void display3()
{
	write_com(0x01);
	displaytwo(6,ahour);
	write_data(table1[0]);
	displaytwo(9,amin);
	write_com(0x80+0x43);
	for(i=0;i<11;i++)
		write_data(table4[i]);
}
Beispiel #11
0
void init()
{
	DULA=0;//U1锁存器直通方式
	WELA=0;//U2锁存器直通方式
	LCDEN=0;
	write_com(0x38);//显示模式设置00111000,见手册
	write_com(0x0c);//光标设置:00001100
	write_com(0x06);//光标设置:00000110
	write_com(0x01);//显示清零,数据指针清零
}
Beispiel #12
0
void init_1602()
{	
	lcdrw=0;
	lcden=0;
	write_com(0x38);	
	write_com(0x0e);
	write_com(0x06);
	write_com(0x01);
	write_com(0x80);
}
Beispiel #13
0
void init_12232()
{
	 rw=0;
    ln=0;
    write_com(0x30);
    write_com(0x02);
    write_com(0x0f);
	 write_com(0x01);	
	 write_com(0x0c);
	 delay(50);
}
Beispiel #14
0
void init() //初始函数
{
	lcdrw=0;
	lcden=0; //E的初始值为低电平,后面的程序给高电平从而满足E为高脉冲
	write_com(0x38); //写入显示模式指令
	write_com(0x0e); //显示是否打开以及
	//光标的设置
	write_com(0x06); //地址指针的加减和整屏是否移动
	write_com(0x01); //清屏指令
	write_com(0x80+0x10); //显示字符的初始位置
}
Beispiel #15
0
void init3()
{
	write_com(0x01);
	write_com(0x80+0x42);
	for(i=0;i<13;i++)
		write_data(table5[i]);
	displaytwo(6,ahour);
	write_data(table1[0]);
	displaytwo(9,amin);
	write_com(0x80+0x06);
}
Beispiel #16
0
void init2()
{
	write_com(0x01);
	write_com(0x80+0x40+0x03); //ÏÔʾnumber
	for(i=0;i<6;i++)
	write_data(table2[i]);
	write_com(0x80+0x06);
	write_data(table1[0]);
	write_com(0x80+0x09);
	write_data(table1[1]);
}
Beispiel #17
0
void display4()
{
		write_com(0x01);
		write_com(0x80+0x46);
		for(i=0;i<5;i++)
			write_data(table5[i]);
		displaytwo(6,ahour);
		write_data(table1[0]);
		displaytwo(9,amin);
		delay(3000);
		write_com(0x01);
}
Beispiel #18
0
int main()
{
	int num;
	int count = 0;

	TMOD=0x01;
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;
	EA=1;
	ET0=1;    //开中断
	TR0=1;
		
	init();
	P2=0xff;
st:	lock=0;
	while(1)
	{	
		write_com(0x01);
		write_lcd(0x40,"save        take");
		num = key();
		if(num == 10)	//存放模式
		{
			NO1 = TH0;
			NO2 = TL0;
			save2();
		}
		if(num == 11) //取出模式
		{
			take2();
		}
	 if(lock>4)
	 {	 
	 lk:	write_com(0x01);
	 	write_lcd(0x00,"    lock on!    ");
		while(1)
		{
			if(key() == 13)
			{
				write_lcd(0x00,"admin:          ");
				if(admin_key() == 1)
				{
					lock = 0;
					 goto st;
				}
				goto lk;
			}
		}
	 }
	}
 	return 0;

}
Beispiel #19
0
void displaytwo(unsigned char add,unsigned char date)
{
	unsigned char shi,ge;
	shi=date/10;
	ge=date%10;
	if(add<10)
	write_com(0x80+add);
	else if(add>=10)
	write_com(0x90+add-10);
	write_data(table[shi]);
	delay(5);
	write_data(table[ge]);
	delay(5);
}
Beispiel #20
0
/**********液晶初始化***************/
void Lcd_initial(void)
{
   //delay(1);
   
   
   write_com(0x30);    //基本指令集动作
   write_com(0x03);    //AC归零,不改变DDRAM的内容
   write_com(0x0c);    //显示0N 游标0FF 游标位反白OFF
   write_com(0x01);    //清屏
   //write_com(0x06);	  //写入时游标右移动
   
  //P5OUT &= ~(BIT0);//rs
  //P5OUT &= ~(BIT1);//rw
}
Beispiel #21
0
// 汉字数组,汉字起始地址,汉字,汉字个数
void write_Chinese(unsigned char *str,unsigned char a,unsigned char b,unsigned char c)
{
  write_com(0x30);
  while(c)
  {
    write_com(Address[a]);
	write_data(str[b]);
	b++;
	write_data(str[b]);
	b++;
	a++;
	c--;
   }
}
Beispiel #22
0
void clear(unsigned char t)
{
	if(t==1)
	{
		write_com(0x80);
	}
	if(t==2)
	{
		write_com(0x80+0x40);
	}
	for(i=0;i<15;i++)
	{
		write_data(' ');
	}
}
Beispiel #23
0
void displayfrequency(unsigned int value)
{
	unsigned char buf[7];
	sprintf(buf,"%u\0",value);
	write_com(0x91);
	for(i=0;i<6;i++)
	{
		write_data(' ');
	}
	write_com(0x91);
	for(i=0;i<strlen(buf);i++)
	{
		write_data(buf[i]);
	}
}
Beispiel #24
0
void LCD_init()	
{
	write_com(0x80);
	for(a=0;a<16;a++)
	{
		write_date(table5[a]);
		delayms(5);
	}
	write_com(0x80+0x40);
	for(a=0;a<12;a++)
	{		
		write_date(table6[a]);
		delayms(5);
	}				   

}
Beispiel #25
0
main()
{
	char t1,th1,th2;
	init_12232();
	aa=0;
	TMOD=0x15;
	TH1=(65536-50000)/256;
	TL1=(65536-50000)%256;
	TH0=0;
	TL0=0;
	EA=1;
	ET1=1;
	TR1=1;
	TR0=1;
   while(1)
   {
		if(flag==1)
		{  
		   flag=0;
			th1=TH0;
			t1=TL0;
			th2=TH0;
			if(th1==th2)
			{
				val=th1*256+t1;
			}
			write_com(0x80);
			displayfour(val);
			TH0=0;
			TL0=0;
		}
	}
}
Beispiel #26
0
void main()
{
	init();
	write_com(0x80);//光标放置在起始处
	for(num=0;num<strlen(line);num++)//strlen来计算字符串长度
	{
		write_data(line[num]);
		delay_ms(5);
	}
	write_com(0x80+0x40);//光标位置调整到第二行
	for(num=0;num<strlen(line2);num++)
	{
		write_data(line2[num]);
		delay_ms(5);
	}
	while(1);
}	
Beispiel #27
0
void write_date(uchar add,uchar dat)   //写入日期函数
{
	uchar shi,ge;
	shi=dat/10;
	ge=dat%10;
	write_com(0x80+add);
	write_data(0x30+shi);
	write_data(0x30+ge);
}
Beispiel #28
0
void write_time(uchar add,uchar date)    //写入时间函数
{
	uchar shi,ge;
	shi=date/10;
	ge=date%10;
	write_com(0x80+0x40+add);
	write_data(0x30+shi);
	write_data(0x30+ge);
}
void clock_init(){
	unsigned char i, j;
	for(i=0;i<5;i++){
 		write_data(first[i]);
	}
	write_com(0x80+0x40);
	for(j=0;j<16;j++){
		write_data(second[j]);
	}
}
Beispiel #30
0
void  write_digital(unsigned char *str,unsigned char a,unsigned char b,unsigned char c)
 {
     while(c)
	{ write_com(Address[a]);
       write_data(str[b]);
       b++;
	    write_data(str[b]);
	   b++;
	   a++;
       c--;}
}