版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.#ifndef _MAIN_H#define _MAIN_H#include #include#include#include#define LcdDataPort P0 /数据端口#ifndef UCHAR_DEF#define UCHAR_DEF#define SGL 1#define DIFF 0#define uint unsigned inttypedef unsigned char uchar;#endifsbit tuidai = P36; /推袋输出sbit supply_1 = P16; /粗喂料口sbit supply_2 = P17; /细喂料口/*MCP3204定义*
2、/sbit AD_CLK = P10;sbit AD_DIN = P11;sbit AD_DOUT = P12;sbit AD_CS = P13;sbit LED = P27;/*ampire12864定义*/sbit Reset = P20; /复位sbit RS = P21; /指令数据选择sbit E = P22; /指令数据控制sbit CS1 = P24; /左屏幕选择,低电平有效sbit CS2 = P25; /右屏幕选择sbit RW = P23; /读写控制sbit busy = P07; /忙标志sbit CE = P26; /总线驱动器使能端sbit BUT = P27;u
3、char p; /临时存储P0口数据uchar key; /键值uchar inisign = 0; /判断是否测皮重信号uchar taodai = 0; /套袋信号uchar setcount = 0; /按键设置计数float xgzl = 40.00; /细给重量uchar tdys = 1; /推袋延时(s)uint tdcount = 0; /推袋延时计数,20为1suchar timeflag = 0;/uchar k = 0; /判断推袋延时或细口给料延时标志uchar xzw = 0; /选择位uchar pzsign = 0; /是否称皮重标志float idata x9;
4、 /采样数据存放数组float idata y9;void SetOnOff(uchar onoff); /开关显示void SelectScreen(uchar screen);/选择屏幕void ClearScreen(uchar screen); /清屏void Show1616(uchar lin,uchar colum,uchar *address);/显示一个汉字void CheckState(); /判断状态void LcdDelay(unsigned int time); /延时void WriteData(uchar dat); /写数据void SendCommand(uc
5、har command); /写指令void SetLine(uchar line); /置行地址void SetColum(uchar colum);/置列地址void SetStartLine(uchar startline);/置显示起始行void InitLcd(); /初始化void ResetLcd(); /复位/*/void int_time0() interrupt 1 using 2 TH0 = 60; TL0 = 176; tdcount +; if(tdcount = 20*tdys) EX0 = 1; /系统闲,可进行设置 EX1 = 1; TR0 = 0; ET0 =
6、 0; tdcount = 0; tuidai = 0;tuidai = 1;timeflag = 0; /*else if(tdcount = 6) & (!k) tdcount = 0;supply_2 = !supply_2; */void int_time1() interrupt 3 using 3 TH1 = 60; TL1 = 176; tdcount +; if(tdcount = 20) taodai = 1; TR1 = 0;tdcount = 0;pzsign = 1; int mcp3204(uchar mode,uchar channel) int i; int c
7、= 0; uchar D1,D0; if(channel & 0x01) D0 = 1; else D0 = 0; if(channel & 0x02) D1 = 1; else D1 = 0; AD_CS = 1; AD_CS = 0; AD_CLK = 0; /起始位 AD_DIN = 1; AD_CLK = 1; AD_CLK = 0; AD_DIN = mode; /模式位 AD_CLK = 1; AD_CLK = 0; AD_DIN = 0; AD_CLK = 1; AD_CLK = 0; AD_DIN = D1; AD_CLK = 1; /通道选择 AD_CLK = 0; AD_D
8、IN = D0; AD_CLK = 1; AD_DOUT = 1; /释放数据线 AD_CLK = 0; AD_CLK = 1; AD_CLK = 0; AD_CLK = 1; /null位跳过 for(i = 0;i 12;i+) c = c1; AD_CLK = 0;AD_CLK = 1;if(AD_DOUT = 1) c = c + 1; AD_CS = 1; return c;/*LCD部分*/void CheckState() E = 1; RS = 0; RW = 1; LcdDataPort = 0xff; while(!busy);void LcdDelay(unsigned
9、int time) while(time -);void WriteData(uchar dat) CheckState(); E = 1; RS = 1; RW = 0; LcdDataPort = dat; E = 0;void SendCommand(uchar command) CheckState(); E = 1; RW = 0; RS = 0; LcdDataPort = command; E = 0;void SelectScreen(uchar screen) /2-全屏,0左屏,1-右屏 switch(screen) case 0 : CS1 = 0; LcdDelay(2
10、); CS2 = 1; LcdDelay(2); break; case 1 : CS1 = 1; LcdDelay(2); CS2 = 0; LcdDelay(2); break; case 2 : CS1 = 0; LcdDelay(2); CS2 = 0; LcdDelay(2); break; void ClearScreen(uchar screen) / screen 2-全屏,0左屏,1-右屏 uchar i,j; SelectScreen(screen); for(i = 0;i 8;i +) SetLine(i); SetColum(0); for(j = 0;j 64; j
11、 +) WriteData(0); void Clear1616(uchar line,uchar colum,uchar screen) /清除16*16的方阵 uchar i,j; SelectScreen(screen); for(j = 0;j 2;j +) SetLine(line + j);SetColum(colum);for(i = 0;i 0 : 7 line = line & 0x07; line = line | 0xb8; /1011 1xxx SendCommand(line);void SetColum(uchar colum) /colum - 0 :63 col
12、um = colum & 0x3f; colum = colum | 0x40; /01xx xxxx SendCommand(colum);void SetStartLine(uchar startline) /startline - 0 : 63 startline = startline & 0x3f; startline = startline | 0xc0; /11xxxxxx SendCommand(startline);void SetOnOff(uchar onoff) /1-开显示 0-关 if(onoff = 1) SendCommand(0x3f); /0011 111x
13、 else SendCommand(0x3e);void ResetLcd() Reset = 0; LcdDelay(2); Reset = 1; LcdDelay(2); RS0 = 0; LcdDelay(2); RS1 = 0; LcdDelay(2); SetOnOff(1);void InitLcd() ResetLcd(); SetOnOff(0); ClearScreen(2); SetLine(0); SetColum(0); SetStartLine(0); SetOnOff(1);void Show1616(uchar lin,uchar colum,uchar *add
14、ress) uchar i; SetLine(lin); SetColum(colum); for(i = 0;i 16;i +) WriteData(*(address +); SetLine(lin + 1); SetColum(colum); for(i = 0;i 16;i +) WriteData(*(address +);/*I2C部分24c04*/*void delayus(int n) int i; for(i = 0;i n;i+) _nop_();void start_iic() SCK = 1; delayus(5); SDA = 1; delayus(5); SDA =
15、 0; delayus(5); SCK = 0;void stop_iic() SDA = 0; SCK = 1; delayus(5); SDA = 1; delayus(5); SCK = 0;void ask_iic() SDA = 0; SCK = 1; delayus(4); SCK = 0; SDA = 1;void nask_iic() SDA = 1; SCK = 1; delayus(4); SCK = 0; SDA = 0;void write_iic(uchar byte) int i; for(i = 0;i 8;i+) if(byte & 0x80) SDA = 1;
16、 else SDA = 0;SCK = 1;delayus(5);SCK = 0;byte = byte 1; SDA=1; while(SDA); SCK=1; delayus(4); if(SDA=0) flag=1; else flag = 0; SCK = 0; uchar read_iic() int i; uchar byte = 0x00; SDA = 1; for(i = 0;i 8;i +) delayus(4);SCK = 1;byte = byte = 46) xgzl = 40;else if(setcount = 2) tdys +; if(tdys = 4) tdy
17、s = 1; /BUTTON3 if(key = 0x17) if(setcount = 1) if(xzw = 1) xgzl -= 1; if(xzw = 2) xgzl -= 0.1; if(xzw = 3) xgzl -= 0.01; if(xgzl = 39) xgzl = 45;else if(setcount = 2) tdys -; if(tdys = 0)tdys = 3; key = 0x00; LcdDataPort = p; EX0 = 1;void int_td() interrupt 2 using 1 EX0 = 0; /系统忙,不能进行设置 EX1 = 0; E
18、T0 = 1; ET1 = 1; timeflag = 0; TR1 = 1; pzsign = 0;/*main.c*/const uchar code SZ_tab = 0x00,0x00,0x00,0x00,0x00,0xE0,0x10,0x08, 0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00, /0 0x00,0x00,0x00,0x00,0x00,0x0F,0x10,0x20, 0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x10,0x10,0xF8, 0x00,
19、0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F, 0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08, 0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x30,0x28,0x24, 0x22,0x21,0x30,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x0
20、0,0x00,0x30,0x08,0x88, 0x48,0x30,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x18,0x20,0x20, 0x20,0x11,0x0e,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x20, 0x10,0xf8,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x07,0x04,0x24, 0x24,0x3f,0x24,0x00,0x00,0x00,0
21、x00,0x00, 0x00,0x00,0x00,0x00,0x00,0xf8,0x08,0x88, 0x88,0x08,0x08,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x19,0x21,0x20, 0x20,0x11,0x0e,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0xe0,0x10,0x88, 0x88,0x18,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x0f,0x11,0x20, 0x2
22、0,0x11,0x0e,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x38,0x08,0x08, 0xc8,0x38,0x08,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x70,0x88,0x08, 0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0
23、x00,0x00,0x1c,0x22,0x21, 0x21,0x22,0x1c,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0xe0,0x10,0x08, 0x08,0x10,0xe0,0x00,0x00,0x00,0x00,0x00,/9 0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x22, 0x22,0x11,0x0f,0x00,0x00,0x00,0x00,0x00;const uchar code HZ_tab = 0x20,0x30,0xac,0x63,0x20,0x18,0x00,0xfc, 0x
24、04,0x04,0xfc,0x04,0x04,0xfc,0x00,0x00, /细 0x22,0x67,0x22,0x12,0x12,0x12,0x00,0xff, 0x41,0x41,0x7f,0x41,0x41,0xff,0x00,0x00, 0x20,0x30,0xac,0x63,0x10,0x20,0x50,0x48, 0x44,0x43,0x44,0x48,0x50,0x20,0x20,0x00, /给 0x22,0x67,0x22,0x12,0x12,0x00,0xfe,0x42, 0x42,0x42,0x42,0x42,0xfe,0x00,0x00,0x00, 0x00,0x08
25、,0x08,0x0a,0xea,0xaa,0xaa,0xaa, 0xff,0xa9,0xa9,0xa9,0xe9,0x08,0x08,0x08, /重 0x00,0x40,0x40,0x48,0x4b,0x4a,0x4a,0x4a, 0x7f,0x4a,0x4a,0x4a,0x4b,0x48,0x40,0x40, 0x00,0x40,0x40,0x40,0xdf,0x55,0x55,0x55, 0xd5,0x55,0x55,0x55,0xdf,0x40,0x40,0x40, /量 0x00,0x40,0x40,0x40,0x57,0x55,0x55,0x55, 0x7f,0x55,0x55,0
26、x55,0x57,0x50,0x40,0x40, 0x10,0x10,0x10,0xff,0x10,0x50,0x20,0xf8, 0x4f,0x48,0x49,0xfa,0x48,0x48,0x08,0x00, /推 0x04,0x44,0x82,0x7f,0x01,0x00,0x00,0xff, 0x22,0x22,0x22,0x3f,0x22,0x22,0x20,0x00, 0x04,0x84,0xc4,0xb4,0x8c,0x00,0x00,0xe4, 0x04,0x04,0xfe,0x42,0x43,0x42,0x00,0x00, /延 0x80,0x44,0x28,0x18,0x2
27、7,0x20,0x40,0x4f, 0x48,0x48,0x4f,0x48,0x48,0x48,0x40,0x00, 0x00,0xfc,0x84,0x84,0x84,0xfc,0x00,0x10, 0x10,0x10,0x10,0x10,0xff,0x10,0x10,0x00, /时 0x00,0x3f,0x10,0x10,0x10,0x3f,0x00,0x00, 0x01,0x06,0x40,0x80,0x7f,0x00,0x00,0x00;const uchar code FH_tab = 0x30,0x30 /.;const uchar code DW_tab = 0x00,0x00,
28、0x80,0x80,0x80,0x80,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /s 0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x08,0xf8,0x00,0x00,0x80,0x80,0x80,0x00, 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,/kg 0x20,0x3f,0x24,0x02,0x2d,0x30,0x20,0x00, 0x00,0x6b,0x94,0x
29、94,0x94,0x93,0x60,0x00;void delay1s() uint i,j; for(i = 0;i 100;i +) for(j = 0;j 1000;j +) _nop_(); void sz() int q,b,s,g; uint j = 0; uchar i,line,colum ; uchar *address ; ClearScreen(2); EX1 = 0; while(1) if(setcount = 0) /writebyte_iic(0x00,xgzl); /writebyte_iic(0x01,tdys);EX1 = 1; break; while(j
30、 160) j +; switch(xzw) case 0:break; case 1:Clear1616(5,16,0);break; case 2:Clear1616(5,34,0);break; case 3:Clear1616(5,48,0);break; j +; if(j = 180) j = 0; switch(setcount - 1) case 0: q = (int)xgzl / 10; b = (int)xgzl % 10; s = (int)(xgzl*10) %10; g = (int)(xgzl*100) % 10; colum = 32; line = 1; ad
31、dress = HZ_tab; for(i = 0;i 2;i +) SelectScreen(0); Show1616(line,colum ,address); colum += 16; address += 32; /向DDRAM中写入数据 colum = 0; for(i = 0;i 2;i +) SelectScreen(1); Show1616(line,colum,address); colum += 16; address += 32; line = 5; colum = 0; for(i = 0;i 4;i +) switch(i) case 0:address = SZ_t
32、ab + q*32;break; case 1:address = SZ_tab + b*32;break; case 2:address = SZ_tab + s*32;break; case 3:address = SZ_tab + g*32;break; SelectScreen(0); Show1616(line,colum ,address);colum += 16;if(colum = 64)colum = 0; address = DW_tab + 32; SelectScreen(1); Show1616(line,colum ,address); colum = 32; Se
33、lectScreen(0); line=line + 1; address = FH_tab; SetLine(line); /显示“.” SetColum(colum); for(i = 0;i 2;i +) WriteData(*(address + 1); break; case 1: Clear1616(5,32,0); Clear1616(5,48,0); Clear1616(5,0,1); colum = 32; line = 1; address = HZ_tab + 4*32; SelectScreen(0); Show1616(line,colum,address); col
34、um += 16; address = HZ_tab + 32; SelectScreen(0); Show1616(line,colum,address); colum = 0; address = HZ_tab + 5*32; for(i = 0;i 2;i +) SelectScreen(1);Show1616(line,colum,address);colum += 16;address += 32; line = 5; colum = 0; address = SZ_tab + tdys*32; SelectScreen(0); Show1616(line,colum,address
35、); colum += 16; address = DW_tab; SelectScreen(0); Show1616(line,colum,address); break; ClearScreen(2);uint lb(uint adata,int i) int k,l; uint adata1; xi = adata; for(k = 0;k 9;k +) yk = xk; for(k = 0;k 8;k +) for(l = k + 1;l xl) adata1 = xk;xk = xl;xl = adata1; adata = x3 + x4 + x5; adata /= 3; for
36、(k = 0;k (float)xgzl) supply_1 = 1;/关闭粗喂料口 /TR0 = 1; if(sj 50) supply_2=1; /关闭细喂料口 /k = 1; if(timeflag = 0) TR0 = 0; tdcount = 0; TR0 = 1; timeflag = 1; if(taodai = 1) /k = 0; TR0 = 0; supply_1 = 0; supply_2 = 0; taodai = 0; /粗细喂料口全开 j+;if(j = 380) j = 0; sj = sj * 100; q = (int) sj / 1000 % 10; b =
37、 (int) sj /100 % 10; s = (int) sj /10 % 10; g = (int) sj % 10; colum = 32; line = 1; address = HZ_tab + 64; for(i = 1;i 3;i +) if(i 63) colum = 0; address += 32; /向DDRAM中写入数据 line = 5; colum = 0; if(q != 0) address = SZ_tab + q*32; SelectScreen(0);Show1616(line,colum ,address); else Clear1616(line,c
38、olum,0); colum = 16; for(i = 0;i 3; i +) switch(i) case 0:address = SZ_tab + b*32;break; case 1:address = SZ_tab + s*32;break; case 2:address = SZ_tab + g*32;break; if(i 63) colum = 0; colum = 32; SelectScreen(0); line=line + 1; address = FH_tab; SetLine(line); /显示“.” SetColum(colum); for(i = 0;i 2;i +) WriteData(*(address + 1); /SelectScreen(2); /SetOnOff(1); / 开显示 /for(i = 0;i 50;i +) /延时 /LcdDelay(1000); return 0;#ifndef _M
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年品牌汽车短期无偿试用协议版B版
- 2024年度商务楼外墙维修工程承包合同一
- 2024年分公司组建合同样本合同书版B版
- 2024年国际人才引进聘用协议示例
- 2024年客户服务与维修保养协议版B版
- 2024年度企业收购协议样本版B版
- 2024年度全面虫控解决方案协议版B版
- 2024年度固定价进口原材料采购合同版B版
- 2024年度个人对个人健身教练服务合同3篇
- 2024年家装水电安装质量承包协议
- 年产5万吨丁苯橡胶生产工艺设计
- 仪器设备自校校验方法汇编(DOC 130页)
- 光伏电站运行维护规程
- (完整word版)留学人员学历认证授权声明模板
- 基本不等式 教学设计
- 普通生物学陈阅增习题(共15页)
- Tip-edge Plus差动直丝弓技术
- 威斯敏斯特小要理问答(修正版)
- 里奇SR-20管线探测仪中文使用说明书
- 幕墙龙骨技术交底
- 核桃树枝治癌偏方
评论
0/150
提交评论