基于单片机的实用电子称的设计课程设计毕业设计.doc
《基于单片机的实用电子称的设计课程设计毕业设计.doc》由会员分享,可在线阅读,更多相关《基于单片机的实用电子称的设计课程设计毕业设计.doc(26页珍藏版)》请在三一办公上搜索。
1、#include#include#include#includeuchar ad_data;uchar ch2;uchar ds5;sbit ADCS =P35; sbit ADDI =P37; sbit ADDO =P37; sbit ADCLK =P36;sbit FUWEI=P34;sbit KAISHI=P33;float press;float price;float total_price;float danjia=2.35,3.56,5.67,4.58,8.96,2.65,5.89,2.19;char *mingcheng=商品代码;void delay(uint z)uint
2、x,y;for(x=z;x0;x-)for(y=110;y0;y-);void bcdtocha(uchar cha)ch0=cha/16+0;ch1=cha%16+0;void flotocha(float t) uint tt; tt=(t*100+0.5); ds0=tt/1000+0; ds1=tt%1000/100+0; ds2=46; ds3=tt%1000%100/10+0; ds4=tt%10+0;/*读ADC0832函数* */采集并返回uchar adc0832() /AD转换,返回结果channel为初始值uchar channel=2; uchar i=0; uchar
3、 j; uint dat=0; uchar ndat=0; ADDI=1; _nop_(); _nop_(); ADCS=0;/拉低CS端 _nop_(); _nop_(); ADCLK=1;/拉高CLK端 _nop_(); _nop_(); ADCLK=0;/拉低CLK端,形成下降沿1 _nop_(); _nop_(); ADCLK=1;/拉高CLK端 ADDI=channel&0x1; _nop_(); _nop_(); ADCLK=0;/拉低CLK端,形成下降沿2 _nop_(); _nop_(); ADCLK=1;/拉高CLK端 ADDI=(channel1)&0x1; _nop_()
4、; _nop_(); ADCLK=0;/拉低CLK端,形成下降沿3 ADDI=1;/控制命令结束 _nop_(); _nop_(); dat=0; for(i=0;i8;i+) dat|=ADDO;/收数据 ADCLK=1; _nop_(); _nop_(); ADCLK=0;/形成一次时钟脉冲 _nop_(); _nop_(); dat=1; if(i=7)dat|=ADDO; for(i=0;i8;i+) j=0; j=j|ADDO;/收数据 ADCLK=1; _nop_(); _nop_(); ADCLK=0;/形成一次时钟脉冲 _nop_(); _nop_(); j=j7; ndat=
5、ndat|j; if(i=1; ADCS=1;/拉搞CS端 ADCLK=0;/拉低CLK端 ADDO=1;/拉高数据端,回到初始状态 dat=8; dat|=ndat; return(dat); /return ad bit fuwei()bit cc=1;if(FUWEI=0) FUWEI=1;delay(10);if(FUWEI=0)cc=0; return cc;void disp_week()gettime_1302();bcdtocha(year);write_lcd(96,12,ch);bcdtocha(mon);write_lcd(96,16,ch);bcdtocha(day);
6、write_lcd(96,20,ch);bcdtocha(hour);write_lcd(112,0,ch);bcdtocha(min);write_lcd(112,3,ch);bcdtocha(sec);write_lcd(112,6,ch);switch(week)case 1:write_lcd(112,14,日);break; case 2:write_lcd(112,14,一);break; case 3:write_lcd(112,14,二);break; case 4:write_lcd(112,14,三);break; case 5:write_lcd(112,14,四);br
7、eak; case 6:write_lcd(112,14,五);break; case 7:write_lcd(112,14,六);break; void main() EA=1;EX0=1;IT0=1;lcd_init();init_1302(); clr_lcdall();write_lcd(0,0, -);write_lcd(12,0, 实用电子称的设计 );write_lcd(28,0,-);write_lcd(40,0, 设计人: 张元科 );write_lcd(56,0,-);write_lcd(68,0, 指导教师:姚惠林 );write_lcd(84,0,-);write_lc
8、d(96,0,当前时间: 20 年 月 日 );write_lcd(112,0, : : 星期 );dodisp_week();while(fuwei();delay(100); clr_lcdall(); write_lcd(0,0, 商品名称:商品代码 );write_lcd(16,0,-);write_lcd(36,0,单价: 元/千克 );write_lcd(52,0,重量: 千克 );write_lcd(68,0,总价: 元 );write_lcd(84,0,-);write_lcd(96,0,当前时间: 20 年 月 日 );write_lcd(112,0, : : 星期 );do
9、 disp_week();ad_data=adc0832() ;write_lcd(0,9,mingcheng);total_price=price*press;flotocha(price); write_lcd(36,5,ds);flotocha(press);write_lcd(52,5,ds);flotocha(total_price);write_lcd(68,5,ds);while(fuwei(); delay(100); void int0()interrupt 0P1=0xff;delay(10);switch(P1)case 0xfe:mingcheng=苹果 ; price
10、=danjia0; break;case 0xfd: mingcheng=香蕉 ; price=danjia1; break; case 0xfb: mingcheng=黄瓜 ; price=danjia2; break;case 0xf7: mingcheng=西瓜 ; price=danjia3; break;case 0xef: mingcheng=李子 ; price=danjia4; break;case 0xdf: mingcheng=栗子 ; price=danjia5; break;case 0xbf: mingcheng=橘子 ; price=danjia6; break;c
11、ase 0x7f: mingcheng=雪梨 ; price=danjia7; break; typedef struct typFNT_GB16 / 汉字字模数据结构 signed char Index2; / 汉字内码索引 char Msk32; / 点阵码数据 ;struct typFNT_GB16 code GB_16 = / 数据表 实, 0x01,0x00,0x00,0x80,0x3F,0xFE,0x28,0x04 , 0x46,0x88,0x04,0x80,0x08,0x80,0x06,0x80 , 0x04,0x80,0x7F,0xFE,0x00,0x80,0x01,0x40
12、, 0x02,0x20,0x04,0x10,0x18,0x18,0x60,0x10 ,/*0*/ 用, 0x00,0x00,0x1F,0xFC,0x10,0x84,0x10,0x84 , 0x10,0x84,0x1F,0xFC,0x10,0x84,0x10,0x84 , 0x10,0x84,0x1F,0xFC,0x10,0x84,0x10,0x84 , 0x20,0x84,0x20,0x84,0x40,0x94,0x80,0x88 ,/*1*/ 电, 0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8 , 0x21,0x08,0x21,0x08,0x3F,0xF8,
13、0x21,0x08 , 0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08 , 0x01,0x02,0x01,0x02,0x00,0xFE,0x00,0x00 ,/*2*/子, 0x00,0x00,0x3F,0xF0,0x00,0x20,0x00,0x40 , 0x00,0x80,0x01,0x00,0x01,0x00,0x01,0x04 , 0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00 , 0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00 ,/*3*/ 称, 0x0C,0x80,0x70,0x80,0
14、x10,0xFE,0x10,0x82 , 0xFD,0x24,0x31,0x20,0x32,0x20,0x58,0xB0 , 0x54,0xA8,0x91,0xA4,0x11,0x24,0x12,0x22 , 0x14,0x22,0x10,0x20,0x10,0xA0,0x10,0x40 ,/*4*/ 设, 0x40,0x00,0x21,0xF0,0x31,0x10,0x21,0x10 , 0x01,0x10,0x01,0x10,0xE2,0x0E,0x25,0xF8 , 0x21,0x08,0x21,0x08,0x20,0x90,0x20,0x90 , 0x28,0x60,0x30,0x90
15、,0x23,0x0E,0x0C,0x04 ,/*5*/ 计, 0x40,0x20,0x20,0x20,0x30,0x20,0x20,0x20 , 0x00,0x20,0xF3,0xFE,0x10,0x20,0x10,0x20 , 0x10,0x20,0x10,0x20,0x10,0x20,0x12,0x20 , 0x14,0x20,0x18,0x20,0x10,0x20,0x00,0x20 ,/*6*/ 人, 0x01,0x00,0x01,0x80,0x01,0x00,0x01,0x00 , 0x01,0x00,0x01,0x00,0x02,0x80,0x02,0x80 , 0x04,0x80
16、,0x04,0x40,0x08,0x60,0x08,0x30 , 0x10,0x18,0x20,0x0E,0x40,0x04,0x00,0x00 ,/*7*/ 张, 0x00,0x80,0xF8,0x88,0x08,0x8C,0x08,0x90 , 0x78,0xA0,0x40,0xC0,0x40,0x80,0x43,0xFE , 0xF8,0xA0,0x48,0xA0,0x08,0x90,0x08,0x90 , 0x08,0x88,0x08,0xA6,0x29,0xC4,0x10,0x80 ,/*8*/ 元, 0x00,0x00,0x1F,0xF8,0x00,0x00,0x00,0x00 ,
17、 0x00,0x00,0x7F,0xFE,0x04,0x40,0x04,0x40 , 0x04,0x40,0x04,0x40,0x08,0x40,0x08,0x40 , 0x10,0x42,0x20,0x42,0x40,0x3E,0x00,0x00 ,/*9*/ 科, 0x06,0x08,0x78,0x88,0x08,0x48,0x08,0x48 , 0xFE,0x08,0x18,0x88,0x1C,0x48,0x2A,0x48 , 0x28,0x0E,0x48,0x78,0x8B,0x88,0x08,0x08 , 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08
18、 ,/*10*/ 学, 0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90 , 0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40 , 0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80 , 0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00 ,/*11*/ 号, 0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10 , 0x1F,0xF0,0x00,0x00,0xFF,0xFE,0x08,0x00 , 0x08,0x00,0x1F,0xF0,0x08,0x
19、10,0x00,0x10 , 0x00,0x10,0x01,0x10,0x00,0xA0,0x00,0x40 ,/*12*/指, 0x11,0x00,0x11,0x38,0x11,0xC0,0x11,0x04 , 0xFD,0x04,0x11,0xFC,0x14,0x00,0x19,0xFC , 0x31,0x04,0xD1,0x04,0x11,0xFC,0x11,0x04 , 0x11,0x04,0x11,0x04,0x51,0xFC,0x20,0x00 ,/*13*/导, 0x00,0x00,0x1F,0xF0,0x10,0x10,0x1F,0xF0 , 0x10,0x04,0x10,0x
20、04,0x0F,0xFC,0x00,0x20 , 0x00,0x20,0xFF,0xFE,0x08,0x20,0x04,0x20 , 0x06,0x20,0x04,0x20,0x00,0xA0,0x00,0x40 ,/*14*/教, 0x08,0x20,0x08,0x20,0x7F,0x20,0x0A,0x7E , 0xFF,0xC4,0x08,0x44,0x10,0xC4,0x3E,0x48 , 0xC4,0x28,0x08,0x28,0x0F,0x10,0xF8,0x10 , 0x08,0x28,0x08,0xC8,0x2B,0x06,0x10,0x04 ,/*15*/ 师, 0x08,0
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 单片机 实用 电子称 设计 课程设计 毕业设计
链接地址:https://www.31ppt.com/p-3939982.html