中北大学2012届本科毕业设计说明书
3.2.2主要程序
#include
bit Receive_Flag; unsigned char *Receive_Pointer; bit SendOver;
unsigned char *Instruc_Pointer; unsigned char data RECEIVED _at_ 0x22; void COM1452(); void Serial_Init();
void Decide_1452(unsigned char *INSTRUC); void Send_message(unsigned char *message); extern void System_UARTO_Init(); extern void Receive(); extern void UARTO_Enable();
#ifndef _1452COM_VALUE #define _1452COM_VALUE #define CALIBRATION 0x00 #define COLLECTION 0x20 #define WATCH 0x10 #define STRAIN 0x40 #define PRESSURE 0x80 #define TEMPRATURE 0x00 #define VIBRATION 0xc0 #endif
unsigned char instruction[7]={0x86,0x16,0x39,0x08,0x59,0x18,0x59};
第21页 共38 页
中北大学2012届本科毕业设计说明书
void main() {
WDT_Disable(); SYSCLK_Init(); System_Port_Init(); System_UART0_Init(); UART0_Enable(); while(1) {
Decide_1452(Instruc_Pointer); }
}
void Decide_1452(unsigned char *INSTRUC) {
Instruc_Pointer = instruction;
if((*Instruc_Pointer & 0x30) == CALIBRATION) // {
if((*Instruc_Pointer & 0xc0) == STRAIN) {
P20 = 1; Serial_Init(); COM1452(); }
if((*Instruc_Pointer & 0xc0) == PRESSURE) {
P21 = 1; Serial_Init();
COM1452(); 页
判断指令是否是校准 第22页 共38 中北大学2012届本科毕业设计说明书
}
}
if( (*Instruc_Pointer & 0x30) == COLLECTION) // 判断是否是指令集
{
if((*Instruc_Pointer & 0xc0) == STRAIN) { }
if((*Instruc_Pointer & 0xc0) == PRESSURE) { }
if((*Instruc_Pointer & 0xc0) == TEMPRATURE)
{ }
if((*Instruc_Pointer & 0xc0) == VIBRATION) { }
}
// 判断指令是否是WATCH
if((*Instruc_Pointer & 0x30) == WATCH) {
if(
{
(*Instruc_Pointer & 0xc0) == STRAIN)
P20 = 1;
Serial_Init();
// UNLOCK0=1,STRAIN 通道可用
COM1452(); }
if( (*Instruc_Pointer & 0xc0) == PRESSURE) {
P21 = 1; Serial_Init(); COM1452();
// UNLOCK1=1,PRESSURE通道可用
} }
第23页 共38
页
中北大学2012届本科毕业设计说明书
}
void COM1452() {
unsigned char n; SendOver = 0;
n = *Instruc_Pointer & 0x0f; // n=数据长度 Instruc_Pointer++; while (n>0) {
if (*Instruc_Pointer == 0x59) {
Send_message(Instruc_Pointer); Instruc_Pointer++; n--; if(n!=0) {
Receive_Pointer = &RECEIVED; } if(n==0) {
Receive_Pointer++; }
Receive_Flag = 1; // Receive
Receive();
} else {
Send_message(Instruc_Pointer);
页
信号的设置 第24页 共38 中北大学2012届本科毕业设计说明书
}
Instruc_Pointer++; n--;
} } if(n==0) {
SendOver = 1; // 发送消息成功 }
void Send_message(unsigned char *message) { }
void Serial_Init() {
ES0 = 0;
TB80 = 1;
SBUF0 = 0xFF; // 初始化串行端口 while (!TI0) ; if (TI0) { TI0 = 0;} SBUF0 = 0x01; while (!TI0) ;
// 初始化串口
ES0 = 0; // 禁用UART 0中断 TB80 = 1; // 第九位设置为1 SBUF0 = *Instruc_Pointer; while (!TI0) ; if (TI0) { TI0 = 0;}
// 等一直到发送成功
第25页 共38 页
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库基于MAX1452的压力传感器校准系统毕业设计(6)在线全文阅读。
相关推荐: