| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1326 人关注过本帖
标题:求助!!关于开发板LPC1114的UART实验,实现下位机通讯控制代码
只看楼主 加入收藏
mir_zhang
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2016-4-11
结帖率:0
收藏
 问题点数:0 回复次数:0 
求助!!关于开发板LPC1114的UART实验,实现下位机通讯控制代码
在网上看了下编写上位机的例子,通过发送16进制的指令控制相对应的IO口的开关状态,可是编写C语言里面LPC1114这个库函数实验的例子没有讲解关于下位机通讯协议的内容及头文件的编写

比如我想要通过下位机 接收的时候先将头码屏蔽然后直接接收功能码 或者取出Byte里面取出功能码的数值去执行不知道这个C代码要怎么写,请各位哥哥指教!!先谢谢了,我编写的代码如下

#include <lpc11xx.h>
#include "LCD22.h"
#include <stdio.h>
#include "systick_delay.h"
#include "gpio.h"



#ifndef CONFIG_ENABLE_DRIVER_ADC
#define CONFIG_ENABLE_DRIVER_ADC    1
#endif

#include "adc.h"
#include "uart.h"

#define Open_ADC0
#define head 0x00
void GPIO_Configuration(void);





int main(void)


{
        uint8_t byte;
        uint8_t byte1;
        
        
  char  a[8];
        int i;

  delay_ms(1000);
        
        UART_init(9600); // 串口,并设置波特率
        ADCInit( ADC_CLK );
        LCD_Initializtion();
        GPIO_Configuration();
/************************************************/
/* 函数功能:串口接收字节数据                       */
/************************************************/
uint8_t UART_recive(void)
{   
    while(!(LPC_UART->LSR & (1<<0)));//等待接收到数据
    return(LPC_UART->RBR);             //读出数据
}

/************************************************/

        
        while(1)
    {
                  byte=UART_recive();           // 等待接收数据
                  delay_ms(5000);
                        byte1=byte-0x00;  //这个应该是错的,我想去掉头码,取功能码
                        printf("%c: ASCII= %d\r\n",byte,byte);
                        
               
                        
                        printf("%c: ASCII= %d\r\n",byte1,byte1);
         
                        
                        
                        i=0;
                        if(i<2000&&byte==head)
                        {
                                i++;
                                
                                        switch(byte1)                                       
                                
                                        {
                                                case 0x01 : GPIOSetValue(PORT2,4,HIGH);break;//lED1 路关  上位机发送0x00 (头码) 0x01(功能码)
                                                case 0x81 : GPIOSetValue(PORT2,4,LOW);break;//lED1 路开
                                                case 0x02 : GPIOSetValue(PORT2,5,HIGH);break;//lED2 路关
                                                case 0x82 : GPIOSetValue(PORT2,5,LOW);break;//lED2 路开
                                                case 0x03 : GPIOSetValue(PORT2,6,HIGH);break;//lED3 路关
                                                case 0x83 : GPIOSetValue(PORT2,6,LOW);break;//lED3 路开
                                                case 0x04 : GPIOSetValue(PORT2,7,HIGH);break;//lED4 路关
                                                case 0x84 : GPIOSetValue(PORT2,7,LOW);break;//lED4 路开
                                                case 0x85 : GPIOSetValue(PORT2,4,HIGH);GPIOSetValue(PORT2,5,HIGH); GPIOSetValue(PORT2,6,HIGH); GPIOSetValue(PORT2,7,HIGH);break;//全局关
                                                case 0x95 : GPIOSetValue(PORT2,4,LOW);GPIOSetValue(PORT2,5,LOW); GPIOSetValue(PORT2,6,LOW); GPIOSetValue(PORT2,7,LOW);break;//全局开
                                                default :break;
                                        }
                                }
                        delay_ms(2000);
                        printf("Use the welcome Open1114 development board!\r\n");

                                 #ifdef        Open_ADC0
                                         printf("ADC Channel%d=%d\r\n",0,ADCRead(0));
                                        sprintf(a,"%10.7f",(ADCRead(0)*3.3)/1024);
                                         #endif
                                 
                                        delay_ms(500);
                                        GUI_Text(50,140,a,White,Red);
                                
                                
                                        GUI_Text(0,220,"Welcome Open1114",White,Red);   
                                        GUI_Text(0,236,"--jason",White,Red);  

                                        LCD_Drawcircle(120,70,40,Blue);
                                        LCD_Drawcircle(120,70,39,Blue);
                                        LCD_DrawLine(0,120,239,120,Blue);
                                        LCD_DrawLine(0,121,239,121,Blue);
}
}
void GPIO_Configuration(void)
{
        /* LED0(PIO2_7)  LED0(PIO2_6)  LED0(PIO2_5)  LED0(PIO2_4) */
        GPIOSetDir(PORT2,4,OUT);
        GPIOSetDir(PORT2,5,OUT);
        GPIOSetDir(PORT2,6,OUT);
        GPIOSetDir(PORT2,7,OUT);        
搜索更多相关主题的帖子: include C语言 开发 哥哥 开关 
2016-04-20 13:49
快速回复:求助!!关于开发板LPC1114的UART实验,实现下位机通讯控制代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060591 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved