国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

用遙控器控制LCD顯示按鍵數值

2019-11-08 19:50:23
字體:
來源:轉載
供稿:網友
#include<reg52.h>#include<stdio.h>#include <intrins.h>#include"./uart/uart.h"#include"./delay/delay.h"#include"1602.h"sbit IR_IN = P3^2;sbit LED0 = P1^0;sbit LED1 = P1^1;sbit LED2 = P1^2;sbit LED3 = P1^3;sbit LED4 = P1^4;sbit LED5 = P1^5;sbit LED6 = P1^6;sbit LED7 = P1^7;unsigned int irtime;bit irok = 0;bit chang_ok = 0;bit startflag = 0;unsigned char irdata[33];unsigned char sbuf[5];unsigned char bitnum = 0;unsigned char str[35];unsigned char buf[4];unsigned char handle_ok = 0;void int0_init(){    IT0 = 1; //設置外部中斷的觸發方式	EA = 1;	EX0 = 1;}void timer0_init(){    EA = 1;	TMOD |= 0x02;	TH0 = 0;	ET0 = 1;	TR0 = 1;}void timer0_isr() interrupt 1{   irtime++;//0.256ms  引導碼 13.5/0.256 = 52 		1.12/0.256 = 4   0.56+1.685/0.256 = 8}/*void chang_num(){	unsigned char i;	str[0] = irdata[0] / 10 + '0';	str[1] = irdata[0] % 10 + '0';	for(i = 0; i < 32; i++)	{		str[i + 2] = irdata[i + 1] + '0';				if(str[i + 2] <= (6 +'0'))		{			str[i + 2] = 0 + '0';		}		else		{			str[i + 2] = 1 + '0';		}	}	str[34] = '/0';	chang_ok = 1;} */void num_handle(){	 unsigned char i,j,k = 1;	 unsigned char temp = 0;	 if(irok == 1)	 {	 	for(i = 0; i < 4; i++)	 	{	 		for(j = 0; j < 8; j++)			{				temp >>= 1;			 	if(irdata[k] > 6)			 	{			 		temp += 0x80;			 	}	 			   			 	k++;			}			buf[i] = temp;	 	}		irok = 0;	}	if((buf[0] + buf[1] == 0xff) && (buf[2] + buf[3] == 0xff))	{		handle_ok = 1;		}}void main(){    timer0_init();	int0_init();	uart_init();	LCD_Init();	LCD_Clear();     while(1)	{	    if(irok == 1)		{//			chang_num();			num_handle();			switch(buf[2])			{			/*	case 0x45: LED0 = ~ LED0;break;				case 0x46: LED1 = ~ LED1;break;				case 0x47: LED2 = ~ LED2;break;				case 0x44: LED3 = ~ LED3;break;				case 0x40: LED4 = ~ LED4;break;				case 0x43: LED5 = ~ LED5;break;				case 0x07: LED6 = ~ LED6;break;				case 0x15: LED7 = ~ LED7;break;							default:break;*/				case 0x45:						sPRintf(sbuf,"%c",1 + 0X30); 						LCD_Write_String(0,0,sbuf);						break;				case 0x46: 							sprintf(sbuf,"%c",2 + 0X30); 						LCD_Write_String(0,0,sbuf);						break;				case 0x47: 							sprintf(sbuf,"%c",3 + 0X30); 						LCD_Write_String(0,0,sbuf);						break;				case 0x44: 							sprintf(sbuf,"%c",4 + 0X30); 						LCD_Write_String(0,0,sbuf);						break;				case 0x40: 							sprintf(sbuf,"%c",5 + 0X30); 						LCD_Write_String(0,0,sbuf);						break;				case 0x43: 							sprintf(sbuf,"%c",6 + 0X30); 						LCD_Write_String(0,0,sbuf);						break;				case 0x07: 						sprintf(sbuf,"%c",7 + 0X30); 						LCD_Write_String(0,0,sbuf);						break;				case 0x15: 							sprintf(sbuf,"%c",8 + 0X30); 						LCD_Write_String(0,0,sbuf);						break;							default:break;			}			if(handle_ok == 1)			{				str[0] = (buf[0] / 16) > 9 ? (buf[0] / 16) + 0x37 : (buf[0] / 16) + 0x30;				str[1] = (buf[0] % 16) > 9 ? (buf[0] % 16) + 0x37 : (buf[0] % 16) + 0x30;				str[2] = (buf[1] / 16) > 9 ? (buf[1] / 16) + 0x37 : (buf[1] / 16) + 0x30;				str[3] = (buf[1] % 16) > 9 ? (buf[1] % 16) + 0x37 : (buf[1] % 16) + 0x30;				str[4] = (buf[2] / 16) > 9 ? (buf[2] / 16) + 0x37 : (buf[2] / 16) + 0x30;				str[5] = (buf[2] % 16) > 9 ? (buf[2] % 16) + 0x37 : (buf[2] % 16) + 0x30;				str[6] = (buf[3] / 16) > 9 ? (buf[3] / 16) + 0x37 : (buf[3] / 16) + 0x30;				str[7] = (buf[3] % 16) > 9 ? (buf[3] % 16) + 0x37 : (buf[3] % 16) + 0x30;				str[8] = '/r';				str[9] = '/n';				handle_ok = 0;			}		   	uart_send_string(str);			irok = 0;		}/*		if(chang_ok == 1)		{			uart_send_string(str);		    uart_send_byte('/n');			chang_ok = 0;		}  */	}}void int0_isr() interrupt 0{    if(startflag)	{		if((irtime > 40)&&(irtime < 60))		{		    bitnum = 0;		} 		irdata[bitnum] = irtime;		bitnum++;		irtime = 0;		if(bitnum == 33)		{		    irok = 1;		//	irdata[33] = '/0';			bitnum = 0;			startflag = 0;		}	}	else	{	    irtime = 0;		startflag = 1;	}}
#include<reg52.h>#include"./uart/uart.h"void uart_init(){	SCON = 0x50; //設置串口工作模式,打開接受允許	//SM0 = 0 ; SM1 = 1 ; REN = 0 ;	//TMOD &= 0x0f;    TMOD |= 0x20; //設置定時器1為工作方式2	TH1 = 0xfd;  //波特率9600									 	//ET1 = 0;	TR1 = 1;	//EA = 1;	//ES = 1;}void uart_send_byte(unsigned char byte){	SBUF = byte;	//TI位自動置1,手動清0	while(!TI);//  while(TI != 1);	TI = 0;}void uart_send_string(unsigned char *string){    while(*string)	{	    uart_send_byte(*string);		string++;	}	  }
#include "1602.h"#include "./delay/delay.h"#define CHECK_BUSY//是否使用判斷忙語句條件,后面使用條件編譯sbit RS = P2^4;   //定義端口 sbit RW = P2^5;sbit EN = P2^6;#define RS_CLR RS=0 #define RS_SET RS=1#define RW_CLR RW=0 #define RW_SET RW=1 #define EN_CLR EN=0#define EN_SET EN=1#define DataPort P0/*------------------------------------------------              判忙函數------------------------------------------------*/ bit LCD_Check_Busy(void)  { #ifdef CHECK_BUSY DataPort= 0xFF;  RS_CLR;  RW_SET;  EN_CLR;  _nop_();  EN_SET; return (bit)(DataPort & 0x80);#else return 0;#endif }/*------------------------------------------------              寫入命令函數------------------------------------------------*/ void LCD_Write_Com(unsigned char com)  {   while(LCD_Check_Busy()); //忙則等待 RS_CLR;  RW_CLR;  EN_SET;  DataPort= com;  _nop_();  EN_CLR; }/*------------------------------------------------              寫入數據函數------------------------------------------------*/ void LCD_Write_Data(unsigned char Data)  {  while(LCD_Check_Busy()); //忙則等待 RS_SET;  RW_CLR;  EN_SET;  DataPort= Data;  _nop_(); EN_CLR; }/*------------------------------------------------                清屏函數------------------------------------------------*/ void LCD_Clear(void)  {  LCD_Write_Com(0x01);  delay_ms(5); }/*------------------------------------------------              寫入字符串函數------------------------------------------------*/ void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)  {             while (*s)  	{      LCD_Write_Char(x,y,*s);      s ++;  x++;    	} }/*------------------------------------------------              寫入字符函數------------------------------------------------*/void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data)  {      if (y == 0)  	{      	LCD_Write_Com(0x80 + x);      	}     else  	{      	LCD_Write_Com(0xC0 + x);      	}         LCD_Write_Data( Data);   }/*------------------------------------------------              初始化函數------------------------------------------------*/ void LCD_Init(void)  {   LCD_Write_Com(0x38);    /*顯示模式設置*/    delay_ms(5);    LCD_Write_Com(0x38);    delay_ms(5);    LCD_Write_Com(0x38);    delay_ms(5);    LCD_Write_Com(0x38);     LCD_Write_Com(0x08);    /*顯示關閉*/    LCD_Write_Com(0x01);    /*顯示清屏*/    LCD_Write_Com(0x06);    /*顯示光標移動設置*/    delay_ms(5);    LCD_Write_Com(0x0C);    /*顯示開及光標設置*/}   
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泽库县| 自治县| 台州市| 从化市| 海口市| 崇义县| 沧源| 内江市| 满洲里市| 辰溪县| 山阳县| 扎囊县| 循化| 胶南市| 昭觉县| 合肥市| 新田县| 柯坪县| 沙田区| 江口县| 阿荣旗| 楚雄市| 梨树县| 渝北区| 中山市| 玉门市| 长治县| 阿瓦提县| 安达市| 维西| 博罗县| 那坡县| 磐石市| 太康县| 巫山县| 晋宁县| 沁水县| 文登市| 弥渡县| 连平县| 诏安县|