📄 can_下位机.c
字号:
#include <REGX52.H>
#include <intrins.h>
#include <absacc.H>
#include <LCD24064.h>
#include <SJA1000.h>
#include <KEY8255.h>
#include <ADC0809.h>
//#include <6264.h>
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
/***********************************************************
菜单子函数声明
************************************************************/
void input_xuehao(uchar n);
void manu_xuehao(void);
void send_xuexiao(uchar dev_id,uchar num);
void manu_contact1(void);
void manu_contact2(void);
void manu_contact3(void);
void manu_major(void);
void manu_11(void);
void manu_111(bit b);
void manu_112(bit c);
void manu_12(void);
void manu_14(void);
void manu_13(void);
void manu_131(void);
void signal_num(void);
void grid1(uchar j);
void send_onedata(uchar para_id,uchar one_dat,uchar num);
uchar xuehao[12],xuehao_num=0; //全局变量用于装学号个数
uchar xuehao1[6]={0},xuehao2[6]={0},xuehao3[6]={0},xuehao4[6]={0},xuehao5[6]={0}; //全局变量用于装学号
uchar grid_ack=0;
uchar buf[10],ID2[4]; ////接收数据缓冲区和ID符区
uchar ADC_dat[3];
uchar code str1[]={'u'-32,'V'-32,'-'-32,'>'-32,'1'-32,','-32,'m'-32,'V'-32,'-'-32,'>'-32,'2'-32,','-32,'V'-32,'-'-32,'>'-32,'3'-32,0};
uchar code str2[]={'u'-32,'A'-32,'-'-32,'>'-32,'4'-32,','-32,'m'-32,'A'-32,'-'-32,'>'-32,'5'-32,','-32,'A'-32,'-'-32,'>'-32,'6'-32,0};
//uchar code str3[]={'H'-32,'z'-32,'-'-32,'>'-32,'7'-32,','-32,'k'-32,'H'-32,'z'-32,'-'-32,'>'-32,'8'-32,0};
uchar code str4[]={'H'-32,'z'-32,'-'-32,'>'-32,'7'-32,','-32,'k'-32,'H'-32,'z'-32,'-'-32,'>'-32,'8'-32,0};
/***********************************************************
主函数
************************************************************/
void main(void)
{
bit liangc_on=0,grid_on=0; ////量程标志位
uchar PA_8255;
uchar key,manu_count=1,manu_temp=1;
uchar manu_count2=11,manu_temp2=11;
uchar manu_count3=111,manu_temp3=111;
uchar ad_dat,grid_x=1,grid_y=1,grid_num=0;
P1_0=0; //关蜂鸣器
init_8255();
LcmInit();
//init_sja(); ////ok //SJA1000初始化////////////////////////////////////////////////////////////
EX0=1; //外部中断0允许控制位
IT0=1; //外部中断0触发方式选择位:IT0=0为低电平触发,IT0=1为下降沿触发
EA=1; //开总中断
id_set:
PA_8255=A_8255;
LcmClear(0);
manu_init(0x10);
manu_xuehao(); ////////////ok /*
//send_xuexiao(PA_8255,xuehao_num+1);/////////////ok
manu_contact1();
//while(grid_ack!=0xa0) //未收到表格参数应答ok
manu_contact2();
///manu_contact3();
Delay(100);
first:
manu_major();
ReverseOneline(0); //反显第一行汉字
while(1)
{
key=key_scan();
if(key==13||key==14)///进入主菜单
{
if(key==13&&manu_temp==1) {manu_count=2; ReverseOneline(0); ReverseOneline(1); } //显示第二行
if(key==14&&manu_temp==1) {manu_count=4; ReverseOneline(0); ReverseOneline(3); } //显示第二行
if(key==13&&manu_temp==2) {manu_count=3; ReverseOneline(1); ReverseOneline(2); } //显示第二行
if(key==14&&manu_temp==2) {manu_count=1; ReverseOneline(1); ReverseOneline(0); } //显示第二行
if(key==13&&manu_temp==3) {manu_count=4; ReverseOneline(2); ReverseOneline(3); } //显示第二行
if(key==14&&manu_temp==3) {manu_count=2; ReverseOneline(2); ReverseOneline(1); } //显示第二行
if(key==13&&manu_temp==4) {manu_count=1; ReverseOneline(3); ReverseOneline(0); } //显示第二行
if(key==14&&manu_temp==4) {manu_count=3; ReverseOneline(3); ReverseOneline(2); } //显示第二行
manu_temp=manu_count;
}
///进入二级菜单
if(key==10&&manu_temp==1)
{
second: manu_11();//显示二级菜单
ReverseOneline(0);
while(1)
{
key=key_scan();
if(key==15) { manu_temp=manu_count=1; manu_temp2=manu_count2=11; goto first; }
if(key==13||key==14)///进入二级菜单
{
if(key==13&&manu_temp2==11) {manu_count2=12; ReverseOneline(0); ReverseOneline(1); } //显示第二行
if(key==14&&manu_temp2==11) {manu_count2=13; ReverseOneline(0); ReverseOneline(2); } //显示第二行
if(key==13&&manu_temp2==12) {manu_count2=13; ReverseOneline(1); ReverseOneline(2); } //显示第二行
if(key==14&&manu_temp2==12) {manu_count2=11; ReverseOneline(1); ReverseOneline(0); } //显示第二行
if(key==13&&manu_temp2==13) {manu_count2=11; ReverseOneline(2); ReverseOneline(0); } //显示第二行
if(key==14&&manu_temp2==13) {manu_count2=12; ReverseOneline(2); ReverseOneline(1); } //显示第二行
manu_temp2=manu_count2;
}
//////进入三级菜单
if(key==10&&manu_temp2==11)//三级菜单1号子菜单
{ manu_temp=manu_count=1; manu_temp2=manu_count2=11; xuehao_num=0; grid_ack=0; goto id_set; }//重新设置ID号
if(key==10&&manu_temp2==12)/////////////////////三级菜单2号子菜单
{
if(liangc_on==0)
manu_111(0);
else
manu_111(1);
ReverseOneline(1);
while(1)
{
key=key_scan();
if(key==13||key==14)//////进入4级菜单
{
if(key==13&&manu_temp3==111) {manu_count3=112; ReverseOneline(1); ReverseOneline(2); } //显示第二行
if(key==14&&manu_temp3==111) {manu_count3=112; ReverseOneline(1); ReverseOneline(2); } //显示第二行
if(key==13&&manu_temp3==112) {manu_count3=111; ReverseOneline(2); ReverseOneline(1); } //显示第二行
if(key==14&&manu_temp3==112) {manu_count3=111; ReverseOneline(2); ReverseOneline(1); } //显示第二行
manu_temp3=manu_count3;
}
if(key==10&&manu_temp3==111) { manu_temp2=manu_count2=11; manu_temp3=manu_count3=111; liangc_on=0; goto second;}
if(key==10&&manu_temp3==112) { manu_temp2=manu_count2=11; manu_temp3=manu_count3=111; liangc_on=1; goto second;}
}//while(1)
}//if(key==10&&manu_temp2==12)
if(key==10&&manu_temp2==13)///////////////////三级菜单3号子菜单
{
if(grid_on==0)
manu_112(0);
else
manu_112(1);
ReverseOneline(1);
while(1)
{
key=key_scan();
if(key==13||key==14)///进入二级菜单
{
if(key==13&&manu_temp3==111) {manu_count3=112; ReverseOneline(1); ReverseOneline(2); } //显示第二行
if(key==14&&manu_temp3==111) {manu_count3=112; ReverseOneline(1); ReverseOneline(2); } //显示第二行
if(key==13&&manu_temp3==112) {manu_count3=111; ReverseOneline(2); ReverseOneline(1); } //显示第二行
if(key==14&&manu_temp3==112) {manu_count3=111; ReverseOneline(2); ReverseOneline(1); } //显示第二行
manu_temp3=manu_count3;
}
if(key==10&&manu_temp3==111) { manu_temp2=manu_count2=11; manu_temp3=manu_count3=111; grid_on=0; goto second;}
if(key==10&&manu_temp3==112) { manu_temp2=manu_count2=11; manu_temp3=manu_count3=111; grid_on=1; goto second;}
}//while(1)
}// if(key==10&&manu_temp2==13)
}//if(key==10&&manu_temp==1)
}// if(key==13||key==14)///进入一级菜单
///--------------------完成第1项菜单----------------------
if(key==10&&manu_temp==2)////进入二级菜单2号菜单
{
manu_12();
while(1)
{
key=key_scan();
if(key==15) { manu_temp=manu_count=1; manu_temp2=manu_count2=11; goto first; }
}
}//if(key==10&&manu_temp==2)
///--------------------完成第2项菜单----------------------
if(key==10&&manu_temp==4)////进入二级菜单4号菜单
{
manu_14();
while(1)
{
key=key_scan();
if(key==15) { manu_temp=manu_count=1; manu_temp2=manu_count2=11; goto first; }
}
}//if(key==10&&manu_temp==2)
///--------------------完成第4项菜单----------------------
if(key==10&&manu_temp==3)////进入二级菜单3号菜单
{
third: manu_13();
ReverseOneline(0);
while(1)
{
key=key_scan();
if(key==15) { manu_temp=manu_count=1; manu_temp2=manu_count2=11; goto first; }
if(key==13||key==14)///进入二级菜单
{
if(key==13&&manu_temp2==11) {manu_count2=12; ReverseOneline(0); ReverseOneline(1); } //显示第二行
if(key==14&&manu_temp2==11) {manu_count2=14; ReverseOneline(0); ReverseOneline(3); } //显示第二行
if(key==13&&manu_temp2==12) {manu_count2=13; ReverseOneline(1); ReverseOneline(2); } //显示第二行
if(key==14&&manu_temp2==12) {manu_count2=11; ReverseOneline(1); ReverseOneline(0); } //显示第二行
if(key==13&&manu_temp2==13) {manu_count2=14; ReverseOneline(2); ReverseOneline(3); } //显示第二行
if(key==14&&manu_temp2==13) {manu_count2=12; ReverseOneline(2); ReverseOneline(1); } //显示第二行
if(key==13&&manu_temp2==14) {manu_count2=11; ReverseOneline(3); ReverseOneline(0); } //显示第二行
if(key==14&&manu_temp2==14) {manu_count2=13; ReverseOneline(3); ReverseOneline(2); } //显示第二行
manu_temp2=manu_count2;
}// if(key==13||key==14)///进入二级菜单
if(key==10)///////////////////三级菜单3号子菜单
{
switch (manu_temp2)
{
case 11: { manu_131(); grid1(0); grid_num=0;}; break;///此处添加手动载入表格或自动载入功能if(grid_on==0)... else ...
case 12: { manu_131(); grid1(12); grid_num=1; }; break;
case 13: { manu_131(); grid1(24); grid_num=2;}; break;
case 14: { manu_131(); grid1(36); grid_num=3;}; break;
}// switch (key)
while(1)
{
key=key_scan();
if(key==15) { manu_temp=manu_count=1; manu_temp2=manu_count2=11; grid_x=1; grid_y=1; grid_num=0; goto third; }
//------------------------------------------------------
switch (key)
{
//case 0x00: {;}; break;
case 0x01:
{ ad_dat=ADC0809(2*4); //采集2通道数据
////write6264(add_p++,ad_dat); //保存
////write6264(add_p++,grid_p); //保存数据类型
dat_dispose(ad_dat); //数据处理小数点后2位
PutData1(grid_x*6,grid_y,ADC_dat[0]);
PutChar (grid_x*6+1,grid_y,'.'-32);
PutData1(grid_x*6+2,grid_y,ADC_dat[1]);
PutData1(grid_x*6+3,grid_y,ADC_dat[2]);
send_onedata(grid_x+(grid_y/2)*4+grid_num*12,ad_dat,xuehao_num+1); //////////数据发送
grid_x++;
if(grid_x>4) {grid_x=1; grid_y+=2;}
if(grid_y>5) {grid_x=1; grid_y=1;}
};break;//mA
case 0x02:
{
ad_dat=ADC0809(0); //采集0通道数据
dat_dispose(ad_dat); //数据处理小数点后2位
PutData1(grid_x*6,grid_y,ADC_dat[0]);
PutChar (grid_x*6+1,grid_y,'.'-32);
PutData1(grid_x*6+2,grid_y,ADC_dat[1]);
PutData1(grid_x*6+3,grid_y,ADC_dat[2]);
send_onedata(grid_x+(grid_y/2)*4+grid_num*12,ad_dat,xuehao_num+1); //////////数据发送
grid_x++;
if(grid_x>4) {grid_x=1; grid_y+=2;}
if(grid_y>5) {grid_x=1; grid_y=1;}
}; break; //mV
case 0x03:
{
ad_dat=ADC0809(1*4); //采集1通道数据
dat_dispose(ad_dat); //数据处理小数点后2位
PutData1(grid_x*6,grid_y,ADC_dat[0]);
PutChar (grid_x*6+1,grid_y,'.'-32);
PutData1(grid_x*6+2,grid_y,ADC_dat[1]);
PutData1(grid_x*6+3,grid_y,ADC_dat[2]);
send_onedata(grid_x+(grid_y/2)*4+grid_num*12,ad_dat,xuehao_num+1); //////////数据发送
grid_x++;
if(grid_x>4) {grid_x=1; grid_y+=2;}
if(grid_y>5) {grid_x=1; grid_y=1;}
}; break; //V
//case 0x04: {;}; break; //待扩展
//case 0x05: {;}; break;
//case 0x06: {;}; break;
//case 0x07: {;}; break;
//case 0x08: {;}; break;
//case 0x09: {;}; break;
}
////----------------------------------------------
}//while(1)
}
}//while(1)
}//if(key==10&&manu_temp==3)
///--------------------完成第3项菜单----------------------
}//while(1)
}//main()
/***********************************************************
发送一帧数据
***********************************************************/
void send_onedata(uchar para_id,uchar one_dat,uchar num)
{
uchar iid[4]={0,0,0,0x00}; //0x00代表数据
iid[0]=xuehao1[1]; //20 05 15 01 01 01
iid[1]=xuehao1[4];
iid[2]=xuehao1[5];
xuehao[0]=0;
xuehao[1]=para_id;
xuehao[2]=one_dat;
send_dframe(iid,xuehao); //只有1个学号,发送一帧数据
if(num>1)
{
iid[0]=xuehao2[1]; //20 05 15 01 01 01
iid[1]=xuehao2[4];
iid[2]=xuehao2[5];
send_dframe(iid,xuehao);
}//只有2个学号,发送一帧数据
if(num>2)
{
iid[0]=xuehao3[1]; //20 05 15 01 01 01
iid[1]=xuehao3[4];
iid[2]=xuehao3[5];
send_dframe(iid,xuehao);
}//只有3个学号,发送一帧数据
if(num>3)
{
iid[0]=xuehao4[1]; //20 05 15 01 01 01
iid[1]=xuehao4[4];
iid[2]=xuehao4[5];
send_dframe(iid,xuehao);
}//只有4个学号,发送一帧数据
if(num>4)
{
iid[0]=xuehao5[1]; //20 05 15 01 01 01
iid[1]=xuehao5[4];
iid[2]=xuehao5[5];
send_dframe(iid,xuehao);
}//只有5个学号,发送一帧数据
}
/***********************************************************
子菜单1界面
***********************************************************/
void manu_13(void)
{
LcmClear(0);
showword(symbol5, 0x00,0);
// showword(can_3, 0x10,0);
// showword(shu_3,0x20,0);
showword(biao,0x10,0);
PutChar(4,1,'1'-32);
showword(symbol5, 0x01,0);
//showword(can_3, 0x11,0);
//showword(shu_3,0x21,0);
showword(biao,0x11,0);
PutChar(4,3,'2'-32);
showword(symbol5, 0x02,0);
//showword(can_3, 0x12,0);
//showword(shu_3,0x22,0);
showword(biao,0x12,0);
PutChar(4,5,'3'-32);
showword(symbol5, 0x03,0);
//showword(can_3, 0x13,0);
//showword(shu_3,0x23,0);
showword(biao,0x13,0);
PutChar(4,7,'4'-32);
}
/***********************************************************
测量信号分类显示
***********************************************************/
/*void signal_num(void)
{ /////测量信号分类显示
PutString(0,6,str1);
PutString(0,7,str2);
PutString(18,6,str3);
PutString(18,7,str4);
}
*/
/***********************************************************
grid显示
***********************************************************/
void grid1(uchar j)
{
uchar i;
for(i=6;i<26;i+=6,j++)
{
PutData2(i,0,j+1);
PutData2(i,2,j+5);
PutData2(i,4,j+9);
}
}
/***********************************************************
子菜单1界面
***********************************************************/
void manu_131(void)
{
uchar code str5[]={'p'-32,'a'-32,'r'-32,'a'-32,0};
uchar code str6[]={'v'-32,'a'-32,'l'-32,'u'-32,0};
uchar n,m;
LcmClear(0);
for(m=0;m<0x03;m++)
for(n=0;n<0xf0;n+=0x10)
showword(line2,n+m,0);
for(m=0;m<6;m++)
for(n=4;n<28;n+=6)
PutChar(n,m,'|'-32); //画表格
for(m=0;m<6;m+=2) //显示参数及数据标号
{
PutString(0,m,str5);
PutString(0,m+1,str6);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -