⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.c

📁 uccos2的的源码文件
💻 C
📖 第 1 页 / 共 2 页
字号:
//// 控制接口定义 : 步进电机,A/D,2x2 Keys,键盘,EEPROM,LED,//////#include "control.h"#include "test.h"extern int Lasttimeout;#include "Sms.c"#include "S3C2410.h"void debugstr(const char* buffer,int j){    UART_SendStr(buffer);}U8 Key_Scan( void ){	rGPGCON = rGPGCON & (~(0x0f<<4));		//GPG2,3--INPUT	rGPEDAT = rGPEDAT | (1<<13) ;			//GPE13-- input	Delay( 1 ) ;	rGPGDAT = rGPGDAT & (~(1<<6));			//GPG6---output 0	if( (rGPGDAT&(1<< 2)) == 0 )		return 19 ;		//--------------kscan2	else if( (rGPGDAT&(1<< 3)) == 0 )		return 17 ;		//--------------kscan3	rGPEDAT = rGPEDAT & (~(1<<13)) ;		//GPE13-- output 0	if( (rGPGDAT&(1<< 2)) == 0 )		return 20 ;		//--------------kscan2	else if( (rGPGDAT&(1<< 3)) == 0 )		return 18 ;		//--------------kscan3	return 0xff;}void  KeyScanExit(void){	//重新初始化IO口	rGPGCON = rGPGCON & (~(0x03<<12)) | (0x01<<12);	//GPG6--output	rGPGDAT= rGPGDAT & (~(1<<6));						//output 0	rGPECON = rGPECON & (~(0x03<<26)) | (0x01<<26); 	//GPE13--output	rGPEDAT = rGPEDAT & (~(1<<13));						//output 0	rGPGCON = rGPGCON & (~(0x0f<<4)) | (0x0a<<4);		//GPG2,3--EXINT10,11}void KeyScanInit(void){	//--------------------------------	rGPGCON = rGPGCON & (~(0x03<<12)) | (0x01<<12);	//GPG6--output	rGPGDAT= rGPGDAT & (~(1<<6));						//output 0	rGPECON = rGPECON & (~(0x03<<26)) | (0x01<<26); 	//GPE13--output	rGPEDAT = rGPEDAT & (~(1<<13));						//output 0	rGPGCON = rGPGCON & (~(0x0f<<4)) | (0x0a<<4);		//GPG2,3--EXINT10,11	rGPCUP =  rGPCUP & (~(0x03<<2));					//disable the pullup res	//--------------------------------}int Led_Blink(int light){	return 1;}#define CHIP_ADDR 	0x50#define PAGE_SIZE	0x08static int read_eeprom(int fd, char buff[], int addr, int count){	return 0;}static int write_eeprom(int fd, char  buff[], int addr, int count){	return 0;}int test_eeprom(int addr,char* buf,int len,int iswr){	return(0);}//// 数码管显示#define  ZLG7290 	0x70    /* ZLG7290的IIC地址 */// ZLG7290寄存器地址(子地址)#define  SubKey  	0x01#define  SubCmdBuf 	0x07#define  SubDpRam 	0x10/*********************************************************************************************************** Function name: DelayMS** Descriptions : 软件延时  **延时时间与系统时钟有关**** Input : dly** Output: -** Created Date : 2007-8-2 09:53上午********************************************************************************************************/void DelayMS(unsigned long dly){    int  i;    for(; dly>0; dly--)      for(i=0; i<100; i++);}/*********************************************************************************************************** Function name: ZLG7290_SendCmd** Descriptions : 发送命令(对子地址7、8)** Input : DATA1, 命令1, 对应ZLG7290的CmdBuf0寄存器**         DATA2, 命令2, 对应ZLG7290的CmdBuf1寄存器** Output: 0, Fail**         1, OK** Created Date : 2007-8-2 11:27上午********************************************************************************************************/unsigned char ZLG7290_SendCmd(unsigned char Data1,unsigned char Data2){    unsigned char Data[2];    unsigned char suba[2];	Data[0] = Data1;	Data[1] = Data2;	suba[0] = 1;	suba[1] = SubCmdBuf;	ISendStr(ZLG7290, suba, Data, 2);	DelayMS(10);	return(1);}/*********************************************************************************************************** Function name: ZLG7290_SendBuf** Descriptions : 向显示缓冲区发送数据** Input : *disp_buf, 要发送数据的起始地址**          num, 发送个数** Output: -** Created Date : 2007-8-2 11:28上午********************************************************************************************************/void  ZLG7290_SendBuf(unsigned char *disp_buf,unsigned char num){	unsigned char  i;	for(i=0; i<num; i++)	{		ZLG7290_SendCmd(0x60 + i, *disp_buf);		disp_buf++;	}}/*********************************************************************************************************** Function name: ZLG7290_GetKey** Descriptions : 读按键** Input : -** Output: >0 键值  (低8位为键码,高8位为按键次数)**         =0 无键按下** Created Date : 2007-8-2 11:30上午********************************************************************************************************/unsigned short	Keyboard_GetKey(void){    unsigned char rece[2];    unsigned char suba[2];    InitI2C();    rece[0] = rece[1] =  0;	suba[0] = 1;	suba[1] = SubKey;	IRcvStr(ZLG7290, suba, rece, 2);	DelayMS(10);	return (rece[0] | (rece[1]<<8));}// LED 显示void  LED_Display(const char* str,int flag){		int i,j;		unsigned char ch;		unsigned char dispstr[8];#define DP 			(1<<7)#define FLASH 	(1<<6)#define SP 0X1F		printf("%s\r\n",str);		for( i = 0; i < 8; i ++)			 dispstr[i] = SP;		for( i = 0 ,j = 7; i < 8; i ++ ,j--)		{			  ch = *str++;			  if ( ch == 0 )			  		break;			  if ( ch == '.' )			  	ch = 0x1f | DP;			  else if ( ch >= '0' && ch <= '9')			  {			  	ch -= '0';			  	if ( *str == '.' )			  	{			  		str++;			  		ch |= DP;			  	}			  }			  else			  {			  	 switch(ch)			  	 {	  	 			 default: ch = 0x1f; break;			   	 }			  }			  if ( (flag & (1<<i)) )			  		ch |= FLASH;				dispstr[j] = ch;		}		ZLG7290_SendBuf(dispstr,8);}//char* gettimestr(char* str){	return str;}void SendBuffer(char* comfile,char* buffer,int len){}#if 0char* buffer2str(char* str,const void* pbuf,int len,int flag){	 int i;   char* ptr = str;   unsigned char* buffer = (unsigned char*) pbuf;#define BYTES_PER_LINE 16   for( i = 0; i < len; i++)   {       if( (i % BYTES_PER_LINE) == 0 )       {	   int j = (i+BYTES_PER_LINE-1);	   if ( j > 255 )	       j = 255;	   			if( flag & 0x01 )	   				ptr += sprintf(ptr,"%02x-%02x:",i,j);       }       ptr += sprintf(ptr,"%02x ",buffer[i]);       if( (i % BYTES_PER_LINE) == (BYTES_PER_LINE-1) )     	   ptr += sprintf(ptr,"\r\n");       else if ( (i%8) == 7 )      	   ptr += sprintf(ptr," ");   }   if( *(ptr-1) != '\n')	   ptr += sprintf(ptr,"\r\n");   return str;}#endif#include <stdio.h>#include <stdlib.h>extern volatile unsigned long RunTimeMs;unsigned long GetRunTimeMs(void){    return RunTimeMs;}const char* gstr_MsgState[] =//{"REC UNREAD","REC READ","STO UNSENT","STO SENT","ALL",};{"未读","已读","STO UNSENT","STO SENT","ALL",};int themsgcount = 0;SM_PARAM themsg[20];int ListMessage(char* str){    int i = 0,ret = 0;    char* ptr = str;    memset(themsg,0,sizeof(themsg));    while( ptr != NULL )    {    	ret = gsmParseMessageList(&themsg[i],&ptr);        if( ret > 0 && (themsg[i].state&0X03) < 2 && themsg[i].TP_UD[0] )        {			 sprintf((char*)buf,"\r\n%s +%s %c%c/%c%c/%c%c %c%c:%c%c:%c%c\r\n%s\r\n",	 				 gstr_MsgState[themsg[i].state&0X03],			         themsg[i].TPA,			         themsg[i].TP_SCTS[0],themsg[i].TP_SCTS[1],			         themsg[i].TP_SCTS[2],themsg[i].TP_SCTS[3],			         themsg[i].TP_SCTS[4],themsg[i].TP_SCTS[5],			         themsg[i].TP_SCTS[6],themsg[i].TP_SCTS[7],			         themsg[i].TP_SCTS[8],themsg[i].TP_SCTS[8],			         themsg[i].TP_SCTS[10],themsg[i].TP_SCTS[11],			         themsg[i].TP_UD);            AppendText((char*)buf);            i += ret;        }    }    themsgcount = i;    return i;}#define rUTRSTAT    rUTRSTAT1#define rURXH       rURXH1extern void RecvResponse(int timeout);int SendGprsCmd(const char* str,char* buffer,int len,int timeout){        int i;//        debugstr(str,0);        StatusMessage("命令处理中,请稍候...");        while(*str != '\0')        {            while(!(rUTRSTAT & 0x02)); // 等待发送器THR为空            for(i=0; i<100; i++);            rUTXH1 = *str++;              // 发送数据        }#ifndef INCLUDE_UART1_INTTERUPT        Lasttimeout = 500;#endif        RecvResponse(timeout);        StatusMessage("命令处理结束");	 	return 0;}void ProcessBuffer(char* buffer,int j){}int kbhit2(void){    if(!(rUTRSTAT & 0x1))        return 0;    return 1;}#ifndef INCLUDE_UART1_INTTERUPTint receivefromcom(int comfd,char* buffer,int len,int timeout0){    int rlen = 0;    unsigned long timeout = timeout0;    unsigned long lasttime = RunTimeMs;    timeout += RunTimeMs;    while(1)    {        if( RunTimeMs > timeout )        {            if( rlen > 0 )                Tell2(RunTimeMs,timeout);            break;        }        if( len <= rlen )        {            Tell2(len,rlen);            break;        }        if( rlen > 1 && (lasttime+Lasttimeout ) < RunTimeMs )        {            Tell2(lasttime,RunTimeMs);            break;        }        if( !kbhit2())        {            continue;        }        timeout += 100;        lasttime = RunTimeMs;    	*buffer++ = (rURXH);        rlen++;    }    *buffer = 0; 	return rlen;}#endif/*AT   测试连接是否正确ATE0  关闭回显。程序初始化AT部分首先关闭回显。ATE1  打开回显。使用超级终端测试命令时打开。AT+CGMI 得到厂商信息AT+CGMR 得到版本号AT+CGSN 得到序列号(IMEI)AT+CIMI 得到手机IMSI号码AT+CSCS 获取、设置当前字符集。可设置为GSM或UCS2AT+CBC 获取电量AT+CCLK 获取设置手机时钟AT+CNUM 机身号码。分为线路一和线路二AT+CSQ 当前信号AT+COPS 网络营运商AT+CSCA 短信中心号码AT+CPMS 选择短信储存地点。可选择ME(SIM卡)和MT(机身)AT+CMGL 列出指定状态的短信息的PDU代码AT+CMGR 列出指定序号的短信息PDU代码AT+CMGS 发送短信AT+CMGD 删除指定的短信

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -