流水灯c语言程序www.8051projects.net

  • d6_276969
    了解作者
  • 12.5KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-25 03:13
    上传日期
c语言版的单片机程序,是在www.8051projects.net找到的,也是我们的暑假实践项目,程序还不错,仅供交流!!!!!!!!
homeautomationnew.zip
  • lcd.c
    1.1KB
  • cmd.c
    8.6KB
  • strfunc.c
    499B
  • HA.c
    1KB
  • HA.hex
    11.5KB
  • cmd.h
    224B
  • HAreg.h
    771B
  • serial.h
    222B
  • strfunc.h
    114B
  • lcd.h
    1015B
  • serial.c
    699B
内容介绍
#include "HAreg.h" #include "serial.h" #include "cmd.h" #include "strfunc.h" #include "lcd.h" bit_8 msg1[25],msg2[25],msg3[25],dim=0; extern bit_8 lwidth,flag; void send_status() { const bit_8 code *consts[]={"Reading Status:\n\r", "Tube 1:","\n\rTube 2:", "\n\rBulb 1:","\n\rBulb 2:","\n\rDimmness Level:", "\n\rSwitch 1:","\n\rSwitch 2:", "\n\rSwitch 3:"}; bit_8 code *status[]={"ON","OFF"}; transmit(consts[0]); transmit(consts[1]); if(!tube1) transmit(status[0]); else transmit(status[1]); transmit(consts[2]); if(!tube2) transmit(status[0]); else transmit(status[1]); transmit(consts[3]); if(!bulb1) transmit(status[0]); else transmit(status[1]); transmit(consts[4]); if(!bulb2) transmit(status[0]); else transmit(status[1]); transmit(consts[5]); transmit_byte(dim+0x30); transmit(consts[6]); if(!switch1) transmit(status[0]); else transmit(status[1]); transmit(consts[7]); if(!switch2) transmit(status[0]); else transmit(status[1]); transmit(consts[8]); if(!switch3) transmit(status[0]); else transmit(status[1]); transmit("\n\rmessages sent:\n\r1) "); transmit(msg1); transmit("\n\r2) "); transmit(msg2); transmit("\n\r3) "); transmit(msg3); transmit("\n\r"); while(!ri); ri=0; transmit("\n\rPress ENTER to Continue...\n\r"); } void tube() { bit_8 i; const bit_8 code *tube_str[]={"Select Tube:\n\r", "Tube 1 ->1\n\rTube 2 ->2\n\r", "Tube 1 selected\n\r", "ON ->1\n\rOFF ->2", "Tube 2 selected\n\r" }; transmit(tube_str[0]); transmit(tube_str[1]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': transmit(tube_str[2]); transmit(tube_str[3]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': tube1=0; break; case '2': tube1=1; break; default: transmit("\n\rInvalid Option"); } break; case '2': transmit(tube_str[4]); transmit(tube_str[3]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': tube2=0; break; case '2': tube2=1; break; default: transmit("\n\rInvalid Option"); } break; default: transmit("\n\rInvalid Option"); } while(!ri); ri=0; transmit("\n\rPress ENTER to Continue...\n\r"); } void bulb() { bit_8 i; bit_8 code *bulb_str[]={"Select Bulb:\n\r", "Bulb 1 ->1\n\rBulb 2 ->2\n\r", "Bulb 1 selected\n\r", "ON ->1\n\rOFF ->2", "Bulb 2 selected\n\r", }; transmit(bulb_str[0]); transmit(bulb_str[1]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': transmit(bulb_str[2]); transmit(bulb_str[3]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': bulb1=0; break; case '2': bulb1=1; break; default: transmit("\n\rInvalid Option"); } break; case '2': transmit(bulb_str[4]); transmit(bulb_str[3]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': bulb2=0; break; case '2': bulb2=1; break; default: transmit("\n\rInvalid Option"); } break; default: transmit("\n\rInvalid Option"); } while(!ri); ri=0; transmit("\n\rPress ENTER to Continue...\n\r"); } void switches() { bit_8 i; bit_8 code *switch_str[]={"Select Switch:\n\r", "Switch 1 ->1\n\rSwitch 2 ->2\n\rSwitch 3 ->3\n\r", "Switch 1 selected\n\r", "ON ->1\n\rOFF ->2\n\r", "Switch 2 selected\n\r", "Switch 1 selected\n\r" }; transmit(switch_str[0]); transmit(switch_str[1]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': transmit(switch_str[2]); transmit(switch_str[3]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': switch1=0; break; case '2': switch1=1; break; default: transmit("\n\rInvalid Option"); } break; case '2': transmit(switch_str[4]); transmit(switch_str[3]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': switch2=0; break; case '2': switch2=1; break; default: transmit("\n\rInvalid Option"); } break; case '3': transmit(switch_str[6]); transmit(switch_str[3]); while(!ri); ri=0; while(!ri); ri=0; i=sbuf; while(!ri); ri=0; switch(i) { case '1': switch3=0; break; case '2': switch3=1; break; default: transmit("\n\rInvalid Option"); } break; default: transmit("\n\rInvalid Option"); } while(!ri); ri=0; transmit("\n\rPress ENTER to Continue...\n\r"); } void msg() { bit_8 i; transmit("\n\rEnter your message (max 24 char):"); str_cpy(msg3,msg2); str_cpy(msg2,msg1); for(i=0;i<25;i++) { while(ri!=1); ri=0; if(sbuf!=0x0D) msg1[i]=sbuf; else break; } for(;i<24;i++) msg1[i]=' '; msg1[i]='\0'; transmit("\n\rMessage sent!"); transmit("\n\rPress ENTER to Continue...\n\r"); mesg = 0; } void help() { bit_8 code *help_str[]={"\n\rHome Automation Server Help\n\r", "\n\rPlease Use these commands:", "\n\r", "\n\rCommand Description\n\r", "\n\r\"stat\" - Get status of all peripherals", "\n\r\"tube\" - Switch on/off tubes", "\n\r\"bulb\" - Switch on/off bulbs", "\n\r\"swch\" - Switch on/off switches", "\n\r\"dimm\" - Change dimmness of bulb", "\n\r\"msg\" - Send a message (max 3 messages)", "\n\r\"?\" - Display help menu.\n\r\n\r"}; transmit(help_str[0]); transmit(help_str[1]); transmit(help_str[2]); transmit(help_str[3]); transmit(help_str[4]); transmit(help_str[5]); transmit(help_str[6]); transmit(help_str[7]); transmit(help_str[8]); transmit(help_str[9]); transmit(help_str[10]); transmit("\n\rPress ENTER to Continue...\n\r"); while(!ri); ri=0; } void show_msg() { bit_8 i=0,j; bit_8 code trans[]={"\n\rServer Busy!\n\r"}; bit_8 code lcd_str1[]={"1) "}; bit_8 code lcd_str2[]={"2) "}; bit_8 code lcd_str3[]={"3) "}; DISABLE_INT while(enter==0); while(1) { transmit(trans); lcd_sendcommand(RETURN_HOME); lcd_sendcommand(LCD_CLEAR); switch(i) { case 0: lcd_sendstr(lcd_str1); for(j=0;j<25;j++) { if(j==13) lcd_sendcommand(0xC0); lcd_sendchar(msg1[j]); } break; case 1: lcd_sendstr(lcd_str2); for(j=0;j<25;j++) { if(j==13) lcd_sendcommand(0xC0); lcd_sendchar(msg2[j]); } break; case 2: lcd_sendstr(lcd_str3); for(j=0;j<25;j++) { if(j==13) lcd_sendcommand(0xC0); lcd_sendchar(msg3[j]); } break; } while(enter!=0&&up!=0&&down!=0); if(enter==0) { while(enter==0); goto exit; } if(up==0) { i++; if(i==3) i=0; while(up==0); } if(down==0) { i--; if(i==0xFF||i==-1) i=2; while(down==0); } } exit: lcd_sendcommand(LCD_CLEAR); lcd_sendcommand(RETURN_HOME); lcd_sendchar(1); lcd_sendchar(2); lcd_sendstr(" Read"); lcd_sendcommand(0xC0); lcd_sendchar(3); lcd_sendchar(4); lcd_sendstr(" Message!"); transmit("\n\rPress ENTER to Continue...\n\r"); fl
评论
    相关推荐