无线点菜系统基于NRF2401无线芯片和51单片机
所有源代码和电路图下载:
无线点菜系统.zip
(235.54 KB, 下载次数: 216)
部分源码预览:
- #include<stdio.h>
- #include"delay.h"
- #include"NRF2401.H"
- sbit RS = P2^4;
- sbit RW = P2^5;
- sbit E = P2^6;
- sbit RES = P2^3;
- sbit PSB = P2^1;
- sbit PAUSE = P3^0;
- #define DataPort P0
- unsigned char *num[10]={"0","1","2","3","4","5","6","7","8","9"};
- unsigned char i=1;
- unsigned char temp[8];
- unsigned char tf =0;
- unsigned char RxBuf[20]={0};
- /*------------------------------------------------
- 检测忙位
- ------------------------------------------------*/
- void Check_Busy()
- {
- RS=0;
- RW=1;
- E=1;
- DataPort=0xff;
- while((DataPort&0x80)==0x80);//忙则等待
- E=0;
- }
- /*------------------------------------------------
- 写命令
- ------------------------------------------------*/
- void Write_Cmd(unsigned char Cmd)
- {
- Check_Busy();
- RS=0;
- RW=0;
- E=1;
- DataPort=Cmd;
- DelayUs2x(5);
- E=0;
- DelayUs2x(5);
- }
- /*------------------------------------------------
- 写数据
- ------------------------------------------------*/
- void Write_Data(unsigned char Data)
- {
- Check_Busy();
- RS=1;
- RW=0;
- E=1;
- DataPort=Data;
- DelayUs2x(5);
- E=0;
- DelayUs2x(5);
- }
- /*------------------------------------------------
- 液晶屏初始化
- ------------------------------------------------*/
- void Init_ST7920()
- {
- DelayMs(40); //大于40MS的延时程序
- PSB=1; //设置为8BIT并口工作模式
- DelayMs(1); //延时
- RES=0; //复位
- DelayMs(1); //延时
- RES=1; //复位置高
- DelayMs(10);
- Write_Cmd(0x30); //选择基本指令集
- DelayUs2x(50); //延时大于100us
- Write_Cmd(0x30); //选择8bit数据流
- DelayUs2x(20); //延时大于37us
- Write_Cmd(0x0c); //开显示(无游标、不反白)
- DelayUs2x(50); //延时大于100us
- Write_Cmd(0x01); //清除显示,并且设定地址指针为00H
- DelayMs(15); //延时大于10ms
- Write_Cmd(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位,光标从右向左加1位移动
- DelayUs2x(50); //延时大于100us
- }
- /*------------------------------------------------
- 显示字符串
- x:横坐标值,范围0~8
- y:纵坐标值,范围1~4
- ------------------------------------------------*/
- void LCD_PutString(unsigned char x,unsigned char y,unsigned char code *s)
- {
- switch(y)
- {
- case 1: Write_Cmd(0x80+x);break;
- case 2: Write_Cmd(0x90+x);break;
- case 3: Write_Cmd(0x88+x);break;
- case 4: Write_Cmd(0x98+x);break;
- default:break;
- }
- while(*s>0)
- {
- Write_Data(*s);
- s++;
- DelayUs2x(50);
- }
- }
- /*------------------------------------------------
- 显示菜名
- ------------------------------------------------*/
- void Dispaly(void)
- {
- switch(RxBuf[1])
- {
- case 1:LCD_PutString(0,i," 01.鱼香肉丝 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 2:LCD_PutString(0,i," 02.宫保鸡丁 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 3:LCD_PutString(0,i," 03.麻婆豆腐 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 4:LCD_PutString(0,i," 04.红烧鲤鱼 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 5:LCD_PutString(0,i," 05.老醋花生 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 6:LCD_PutString(0,i," 06.炒茼蒿 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 7:LCD_PutString(0,i," 07.酱脊骨 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 8:LCD_PutString(0,i," 08.拌蕨粉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 9:LCD_PutString(0,i," 09.爆炒腰花 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 10:LCD_PutString(0,i," 10.炖牛肉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 11:LCD_PutString(0,i," 11.蒜苗炒肉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 12:LCD_PutString(0,i," 12.葱爆羊肉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 13:LCD_PutString(0,i," 13.葱爆牛肉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 14:LCD_PutString(0,i," 14.孜然羊肉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 15:LCD_PutString(0,i," 15.孜然牛肉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 16:LCD_PutString(0,i," 16.干煸豆角 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 17:LCD_PutString(0,i," 17.干煸两样 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 18:LCD_PutString(0,i," 18.红烧鸡翅 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 19:LCD_PutString(0,i," 19.疙瘩汤 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 20:LCD_PutString(0,i," 20.溜肥肠 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 21:LCD_PutString(0,i," 21.水煮肉片 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 22:LCD_PutString(0,i," 22.水煮鱼 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 23:LCD_PutString(0,i," 23.醋溜白菜 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 24:LCD_PutString(0,i," 24.角瓜炒肉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 25:LCD_PutString(0,i," 25.五香牛肉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 26:LCD_PutString(0,i," 26.盐水大虾 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 27:LCD_PutString(0,i," 27.白菜豆腐 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 28:LCD_PutString(0,i," 28.韭菜鸡蛋 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 29:LCD_PutString(0,i," 29.蒜台炒肉 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- case 30:LCD_PutString(0,i," 30.红烧排骨 ");
- LCD_PutString(7,i,num[RxBuf[2]]);
- break;
- default:break;
- }
- }
- /*------------------------------------------------
- 清屏
- ------------------------------------------------*/
- void ClrScreen()
- {
- Write_Cmd(0x01);
- DelayMs(15);
- }
- /*------------------------------------------------
- 主程序
- ------------------------------------------------*/
- void main()
- {
-
- init_NRF24L01();
- Init_ST7920();
- DelayMs(500);
- LCD_PutString(0,1," -无线点菜系统- ");
- while(1)
- {
- SetRX_Mode();
- nRF24L01_RxPacket(RxBuf);
- if(RxBuf[0]==0XAA)
- {
- if(i==5)
- {
- i=1;
- }
- Dispaly();
- RxBuf[0] = 0x00;
- RxBuf[1] = 0x00;
- RxBuf[2] = 0x00;
- i++;
- }
- }
- }
复制代码
|