《数控直流电流源程序文件》由会员分享,可在线阅读,更多相关《数控直流电流源程序文件(24页珍藏版)》请在金锄头文库上搜索。
1、. . . ./*跳线说明:1)将EXP-LM3S811板卡上JP9、JP13跳至左侧(短接1-2);2)将EXP-min_system_board板卡上JP13、JP14、JP15、JP16跳至右侧(短接2-3。操作过程:1)将EXP-min_system_board板卡上K1拨动开关拨至ON状态,给液晶上电;2)调节RP1电位器,使液晶有合适的背光;3)上电,编译并下载程序,复位后全速运行程序;观察液晶显示的内容,再修改程序使之显示自己的内容。*/#include systemInit.h#include ADS7886.h#include TLV5616.h#include timer.
2、h#define CTL_PERIPH SYSCTL_PERIPH_GPIOC /控制液晶所用的片内端口外设定义#define CTL_PORT GPIO_PORTC_BASE#defineSCK GPIO_PIN_4 / 定义信号SCK#defineSID GPIO_PIN_5 / 定义信号SID#define CS GPIO_PIN_6 / 定义信号CS#define PSB GPIO_PIN_7 / 定义信号PSB#define SCK_LGPIOPinWrite(CTL_PORT,SCK,0x00) /定义信号输出低电平#define SID_LGPIOPinWrite(CTL_POR
3、T,SID,0x00) #define CS_LGPIOPinWrite(CTL_PORT,CS,0x00)#define PSB_LGPIOPinWrite(CTL_PORT,PSB,0x00)#define SCK_HGPIOPinWrite(CTL_PORT,SCK,0xFF)/定义信号输出高电平#define SID_HGPIOPinWrite(CTL_PORT,SID,0xFF) #define CS_HGPIOPinWrite(CTL_PORT,CS,0xFF)#define PSB_HGPIOPinWrite(CTL_PORT,PSB,0xFF)#define SID_READ
4、GPIOPinRead(CTL_PORT,SID)/定义读回的数据#define SID_IN GPIOPinTypeGPIOInput(CTL_PORT,SID)/定义SID信号为输入#define SID_OUT GPIOPinTypeGPIOOutput(CTL_PORT,SID)/定义SID信号为输出#define LED_PERIPH SYSCTL_PERIPH_GPIOB#define LED_PORT GPIO_PORTB_BASE#define LED GPIO_PIN_5#define KEY_PERIPH SYSCTL_PERIPH_GPIOD /KEYS所接的端口#def
5、ine KEY_PORT GPIO_PORTD_BASE#define KEY GPIO_PIN_7|GPIO_PIN_6|GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0#define KEY_HGPIO_PIN_7|GPIO_PIN_6|GPIO_PIN_5|GPIO_PIN_4#define KEY_LGPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0#define key_h_in GPIOPinTypeGPIOInput(KEY_PORT,KEY_H)#define
6、key_l_in GPIOPinTypeGPIOInput(KEY_PORT,KEY_L)#define key_h_out GPIOPinTypeGPIOOutput(KEY_PORT,KEY_H)#define key_l_out GPIOPinTypeGPIOOutput(KEY_PORT,KEY_L)#define SysCtlPeriClkGatingSysCtlPeripheralClockGating /定义睡眠函数#define SysCtlPeriSlpEnableSysCtlPeripheralSleepEnable #define BitRate 115200 / 设定S
7、PI的波特率#define DataWidth 8 / 设定SPI的数据宽度 unsigned char AC_TABLE=0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, /第一行汉字位置0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, /第二行汉字位置 ;/开始菜单 欢迎界面unsigned char Hello1=欢迎使用数控 ;unsigned char Hello2=直流电流源 ;unsigned char Hello3=制作人: ;unsigned char Hello4=chenfangjie;/一级菜单1unsig
8、ned char menu1_1=请输入(202000):; /选择提示unsigned char menu1_2=设值: mA ;/一级菜单1unsigned char menu2_1=设定值: mA; /选择提示unsigned char menu2_2=读取值: A;unsigned char key_val=0;/键值全局变量int A;void keyBoardInit(void)SysCtlPeripheralEnable(KEY_PERIPH); /D口使能开GPIOPinTypeGPIOOutput(KEY_PORT,KEY_H); /扫描信号输出GPIOPinTypeGPIO
9、Input(KEY_PORT,KEY_L);/按键信号输入/键盘扫描程序void keyBoard_scan(void)/如下依次输出行扫描线 /如果有键按下则扫描列线,并获得键值/按键释放判断 unsigned char key_h,key_l;key_val=0;key_l_out;key_h_out; GPIOPinWrite(KEY_PORT,KEY,0xf0); key_h_in; key_h=GPIOPinRead(KEY_PORT,KEY_H);if(GPIOPinRead(KEY_PORT,KEY_H)&0xf0)!=0xf0) SysCtlDelay(5*(TheSysClo
10、ck/3000);if(GPIOPinRead(KEY_PORT,KEY_H)&0xf0)!=0xf0)key_h=GPIOPinRead(KEY_PORT,KEY_H)&0xf0;key_h_out; key_l_out; GPIOPinWrite(KEY_PORT,KEY,0x0f); key_l_in; key_l=GPIOPinRead(KEY_PORT,KEY_L)&0x0f; key_val=key_h+key_l; while(key_l!=0x0f) key_l=GPIOPinRead(KEY_PORT,KEY_L)&0x0f; switch(key_val) case 0xe
11、7: key_val=13;break;case 0xeb: key_val=9;break;case 0xed: key_val=5;break;case 0xee: key_val=1;break;case 0xd7: key_val=14;break;case 0xdb: key_val=10;break;case 0xdd: key_val=6;break;case 0xde: key_val=2;break;case 0xb7: key_val=15;break;case 0xbb: key_val=11;break;case 0xbd: key_val=7;break;case 0
12、xbe: key_val=3;break;case 0x77: key_val=16;break;case 0x7b: key_val=12;break;case 0x7d: key_val=8;break;case 0x7e: key_val=4;break; /LCM端口初始化void init(void) SysCtlPeripheralEnable( CTL_PERIPH); /使能所用的端口 GPIODirModeSet(CTL_PORT, (SCK | PSB | CS ) ,GPIO_DIR_MODE_OUT); /设置信号的方向GPIOPadConfigSet(CTL_PORT, (SCK | PSB | CS ), GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); /设置IO的驱动能力SysCtlPeripheralEnable(LED_PERIPH); GPIOPinTypeGPIOOutput(LED_PORT, LED); GPIOPadConfigSet(LED_PORT, LED, GPIO_STRENGTH_8MA, G