下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、自動(dòng)稱量參考程序 自動(dòng)稱量參考程序.c # include # define fosc 22118400l / *定義通訊協(xié)議*/ # define send_zhen_tou send_data1(0xee); # define send_zhen_wen send_data1(0xff);send_data1(0xfc);send_data1(0xff);send_data1(0xf f); / *定義程序必須有的變量 * */ bit busy = 0;/com1使用 sbit sck = p0;/定義hx711的sck sbit d_out = p0;/定義hx711的d_0ut引腳
2、sbit k_1 = p3; sbit k_2 = p3; sbit k_3 = p3; sbit k_4 = p3; sbit k_5 = p2;/定義了5個(gè)開關(guān)量輸入 sbit step_en = p2; sbit step_dir = p2; / /sbit step_pul = p2;/定義步進(jìn)電機(jī)驅(qū)動(dòng)引腳 sbit jd1 = p1; sbit jd2 = p1;/定義繼電器驅(qū)動(dòng)引腳 / *通信使用命令*/ xdata unsigned char read_hua_mian_id8 = 0xee,0xb1,0x01,0xff,0xfc,0xff,0xff,0xcc; xdata un
3、signed char shua_xin_off8=0xee,0xb3,0x00,0xff,0xfc,0xff,0xff,0xcc; xdata unsigned char shua_xin_on8=0xee,0xb3,0x01,0xff,0xfc,0xff,0xff,0xcc; xdata unsigned char feng_ming8=0xee,0x61,0x32,0xff,0xfc,0xff,0xff,0xcc; / *聲明無需存入eeprom的變量*/ unsigned char send_message20 =0;/發(fā)送幀消息專用數(shù)組 unsigned char read_mess
4、age20 = 0;/接收消息專用緩沖區(qū) unsigned char uart_read_f = 0; unsigned char uart_read_count = 0; unsigned long hx711_ad = 0;/hx711 ad轉(zhuǎn)換結(jié)果 unsigned long ad_bi_jiao = 0; unsigned int step_f = 0;/存放頻率計(jì)算結(jié)果 unsigned int lin_step_f = 10; unsigned char hua_mian_id = 0; float xi_shu_xiao = 0.0; float xi_shu_da = 0.0;
5、 unsigned long mu_biao_liang_1 = 0;/實(shí)際進(jìn)料時(shí),去掉提前量的數(shù)值 第 1 頁 自動(dòng)稱量參考程序.c unsigned long mu_biao_liang_8 = 0;/x0.8的數(shù)值 unsigned long shi_shi_zhi_liang = 0;/動(dòng)態(tài),實(shí)時(shí)質(zhì)量 /*聲明需要存入eeprom的變量*/ unsigned int mi_ma = 0; unsigned int step_fast = 0;/步進(jìn)電機(jī)快速運(yùn)行的頻率 unsigned int step_low = 0;/步進(jìn)電機(jī)慢速運(yùn)行的頻率 unsigned long mu_biao
6、_liang = 0;/目標(biāo)量 unsigned long pian_yi = 0;/質(zhì)量偏移 unsigned char lv_bo = 0;/濾波系數(shù) unsigned int fa_ma_da = 0;/校準(zhǔn)時(shí)大砝碼的 unsigned int fa_ma_zhong = 0;/校準(zhǔn)時(shí)中砝碼質(zhì)量 unsigned int fa_ma_xiao = 0;/校準(zhǔn)時(shí)小砝碼質(zhì)量 unsigned long cai_yang_da = 0;/校準(zhǔn)時(shí),大砝碼采樣值 unsigned long cai_yang_zhong = 0;/較準(zhǔn)時(shí),中砝碼采樣值 unsigned long cai_yang_
7、xiao = 0;/較準(zhǔn)時(shí),小砝碼采樣值 unsigned char liang_du = 130;/默認(rèn)亮度130 float pi_zhong = 0;/定義皮重 /*聲明子函數(shù)*/ void use_k(void); void send_data1(unsigned char dat); void send_str1(char *s); void num_to_message(unsigned long dat); unsigned long hx711_10(void); void step_control(unsigned char k,unsigned int f); void u
8、pdata_zhong_liang(unsigned long ke); void delay_1ms(unsigned char k); void delay_50ms(unsigned int m); void set_txt(unsigned char screen_id,unsigned char control_id,unsigned long dat,unsigned char counter); void ying_jian_ce_shi(void); unsigned int tft_read_txt(unsigned char hua_mian,unsigned char t
9、xt); void shu_ru_mi_ma(void); void tft_show_6bit(unsigned char hua_mian,unsigned char txt,unsigned long num); void can_shu_she_zhi(void); void tft_show_4bit(unsigned char hua_mian,unsigned char txt,unsigned int num); void jiao_cheng(void); unsigned int ass_to_num_4bit(unsigned char *p); unsigned lon
10、g ass_num_dot(unsigned char *p); void te_shu_mi_ma(void); void save_eeprom(unsigned int add,unsigned long dat); unsigned long read_eeprom(unsigned int add); 第 2 頁 自動(dòng)稱量參考程序.c void get_xi_shu(void); float get_zhi_liang(void); unsigned long shi_ji_zhong_liang(void); void mao_pao_pai_xu(unsigned long *a
11、,unsigned char chang_du); void zheng_chang_xia_liao(void); void kuai_su_qing_liao(void); void set_mu_biao_liang(void); /*主函數(shù)*/ void main() p0m1=0;p0m0=0; jd1 = 0;jd2 = 0; p1m1=0;p1m0=0xff; jd1 = 0;jd2 = 0; p2m1=0x10;p2m0=0; p3m1=0;p3m0=0; p4m1=0;p4m0=0; p5m1=0;p5m0=0; scon = 0x50; auxr = 0x15;/com1,
12、com2,控制波特率發(fā)生器 t2l = 0xd0; t2h = 0xff;/波特率設(shè)置 auxr1 |= 0x40; ps = 1; es = 1;/允許串行口中斷 auxr1 |= 0x20; cmod = 0x02; step_f = fosc / 4 / 3000; ccon = 0; ch = 0; cl = 0; ccap0l = step_f; ccap0h = step_f 8; ccapm0 = 0x4d; cr = 0; / */ ea = 1;/允許cpu總中斷 step_en = 1; step_dir = 1; delay_1ms(250);/250ms / *讀取*e
13、eprom*/ mi_ma = read_eeprom(1); step_fast = read_eeprom(2); step_low = read_eeprom(3); mu_biao_liang = read_eeprom(4); 第 3 頁 自動(dòng)稱量參考程序.c pian_yi = read_eeprom(5); lv_bo = read_eeprom(6); fa_ma_da = read_eeprom(7); fa_ma_zhong = read_eeprom(8); fa_ma_xiao = read_eeprom(9); cai_yang_da = read_eeprom(10
14、); cai_yang_zhong = read_eeprom(11); cai_yang_xiao = read_eeprom(12); liang_du = read_eeprom(13); pi_zhong = read_eeprom(14); / */ k_1 = 1; k_2 = 1; k_3 = 1; k_4 = 1; / k_5 = 1; *停留在開機(jī)畫面*/ while(hua_mian_id = 0) send_str1(read_hua_mian_id); / /獲取有效的畫面id結(jié)果 if(read_message1 = 0xb1) / *發(fā)送亮度控制信號(hào)*/ send_
15、zhen_tou; send_data1(0x60); send_data1(liang_du); send_zhen_wen;/將亮度調(diào)暗到130 delay_1ms(100);/200ms,使傳感器電源供給穩(wěn)定 get_xi_shu();/計(jì)算稱重系數(shù) pi_zhong = hx711_10(); set_txt(1,6,mu_biao_liang,6);/工作界面的目標(biāo)量 delay_1ms(100); mu_biao_liang_1 = mu_biao_liang - pian_yi;/計(jì)算去掉提前量 的值 mu_biao_liang_8 = mu_biao_liang_1 * 8 / 10;/0.8 send_str1(feng_ming); jd1 = 1; /*主循環(huán)*/ while(1) send_str1(read_hua_mian_id); delay_1ms(5); if(read_message1 = 0xb1) switch(hua_mian_id) hua_mian_id = 0xfe; /case 0x01: 工作界面 use_k();/處理按鍵按下結(jié)果 / break; updata_zhong_liang(shi_ji_zhong_liang(); ca
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 出租車運(yùn)輸行業(yè)市場(chǎng)調(diào)研分析報(bào)告
- 便攜式取暖器產(chǎn)品供應(yīng)鏈分析
- 碗碟晾干架項(xiàng)目營銷計(jì)劃書
- 紙制筷子套細(xì)分市場(chǎng)深度研究報(bào)告
- 醫(yī)用或獸醫(yī)用培養(yǎng)細(xì)菌用介質(zhì)產(chǎn)品供應(yīng)鏈分析
- 醫(yī)用減肥茶產(chǎn)品供應(yīng)鏈分析
- 體育訓(xùn)練服務(wù)行業(yè)相關(guān)項(xiàng)目經(jīng)營管理報(bào)告
- 電腦游戲操縱桿用充電器項(xiàng)目運(yùn)營指導(dǎo)方案
- 物位變送器項(xiàng)目營銷計(jì)劃書
- 樂譜架產(chǎn)業(yè)鏈招商引資的調(diào)研報(bào)告
- 2024世界糖尿病日糖尿病與幸福感糖尿病健康教育課件
- 公務(wù)員2018年國考《申論》真題卷及答案(副省級(jí))
- 2024年基金從業(yè)資格證(含三個(gè)科目)考前必刷必練題庫500題(含真題、必會(huì)題)
- 2024年統(tǒng)編版新教材語文小學(xué)一年級(jí)上冊(cè)全冊(cè)單元測(cè)試題及答案(共8單元)
- 兩彈一星精神(教學(xué)設(shè)計(jì))-2023-2024學(xué)年小學(xué)科學(xué)課后服務(wù)科普課程
- 2024年共青團(tuán)入團(tuán)積極分子考試題庫(含答案)
- 融媒體內(nèi)容策劃與制作競(jìng)賽考試參考題庫(含答案)
- 保安隊(duì)排班表
- EN779-2012一般通風(fēng)過濾器——過濾性能測(cè)定(中文版)
- 沁園春·疊嶂西馳.中職課件電子教案
- 某化工廠安全評(píng)價(jià)報(bào)告現(xiàn)狀評(píng)價(jià)
評(píng)論
0/150
提交評(píng)論