![]() |
發(fā)布時間: 2019-12-10 17:53
正文摘要:本帖最后由 愛自由O 于 2019-12-10 17:59 編輯 一個矩陣鍵盤控制蜂鳴器,一個數(shù)碼管程序,怎么合并使用,源碼已貼出,#include "reg52.h" #include "key.h" sbit led=P2^5; unsigned int Tab_F[]={440, ... |
那你就把key.h這個語句屏蔽或者刪除,不然編譯肯定找不到報錯 |
huwqly 發(fā)表于 2019-12-12 08:11 key.h是那個矩陣鍵盤掃描,現(xiàn)在不用了,用的獨立鍵盤 |
謝謝大家![]() |
這兩個程序本來就是一種完成基本功能的學(xué)習(xí)代碼,其缺陷是非常明顯的,在實際應(yīng)用中很少采用。兩者合并后其基本功能都有,但不完善。按鍵反應(yīng)不靈敏,蜂鳴器工作期間明顯干擾數(shù)碼管顯示。
![]()
|
gai.c(2): warning C318: can't open file 'key.h' 這里提示你 不能打開'key.h' |
#include "key.h"這個是外部引用,你要找到你原先復(fù)制那段鍵盤的程序,把里面的 "key.h"復(fù)制添加到你的這個工程 |
huwqly 發(fā)表于 2019-12-11 13:19 Build target 'Target 1' assembling STARTUP.A51... compiling gai.c... gai.c(2): warning C318: can't open file 'key.h' GAI.C(68): error C202: 'GPIO_KEY': undefined identifier GAI.C(70): error C202: 'GPIO_KEY': undefined identifier GAI.C(73): error C202: 'GPIO_KEY': undefined identifier GAI.C(76): error C202: 'GPIO_KEY': undefined identifier GAI.C(77): error C202: 'GPIO_KEY': undefined identifier GAI.C(85): error C202: 'GPIO_KEY': undefined identifier GAI.C(86): error C202: 'GPIO_KEY': undefined identifier GAI.C(93): error C202: 'GPIO_KEY': undefined identifier GAI.C(111): error C237: '_delay': function already has a body GAI.C(146): error C141: syntax error near '{' GAI.C(164): error C141: syntax error near '}' compiling key.c... Target not created |
huwqly 發(fā)表于 2019-12-11 13:19 好的好的,我試下程序,謝謝謝謝 |
PDDDF 發(fā)表于 2019-12-11 09:23 一個是引用,一個是矩陣鍵盤對應(yīng)蜂鳴器頻率,shuxian是一個數(shù)碼管顯示的程序,好像引腳使用重復(fù)了 |
這是兩個程序代碼段,合并很簡單,要寫出你想要顯示哪些內(nèi)容或者要達到什么目的,下面是合并的結(jié)果: #include "reg52.h" #include "key.h" /////////移到這里////////////////////// //#include <reg52.h> typedef unsigned char uchar; typedef unsigned int uint; sbit LSA=P2^2; sbit LSB=P2^3; sbit LSC=P2^4; uchar smg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f}; ///////////////////////////////// sbit led=P2^5; unsigned int Tab_F[]={440,494,554,220, 440,494,554,220, 554,587,659,554, 587,659,999,}; unsigned char key_num; unsigned int Pinlv,Shichang; bit beep; void Timer0Init() { TMOD|=0X01; TH0=(65536-92)/256; TL0=(65536-92)%256; ET0=1; //T0中斷 EA=1; //cpu總中斷 TR0=1; } /*/////////////下面這段聲明移到最后面的main主程序里面 void main() { Timer0Init(); while(1) { key_num=KeyDown(); if(key_num!=0xff) { Pinlv=Tab_F[key_num]; beep=1; Shichang=0; EA=1; } }; } //////////////////////*/ void Timer0() interrupt 1 { static unsigned int i; TH0=(65536-92)/256; TL0=(65536-92)%256; i++; if(i>(5000/Pinlv)) { if(beep==1) {led=~led;} i=0; } Shichang++; if(Shichang==1000) { beep=0; led=0; EA=0; } } //===========================分隔// #include "key.h" unsigned char KeyValue=0; void delay(unsigned int i) { while(i--); } unsigned char KeyDown(void) { char a=0; GPIO_KEY=0x0f; if(GPIO_KEY!=0x0f) { delay(1000); if(GPIO_KEY!=0x0f) { GPIO_KEY=0X0F; switch(GPIO_KEY) //lie { case(0X07): KeyValue=0;break;// 0111 case(0X0b): KeyValue=1;break;// 1011 case(0X0d): KeyValue=2;break; // 1101 case(0X0e): KeyValue=3;break;// 1110 } GPIO_KEY=0XF0; //hang switch(GPIO_KEY) { case(0X70): KeyValue=KeyValue;break; //0111 case(0Xb0): KeyValue=KeyValue+4;break; case(0Xd0): KeyValue=KeyValue+8;break; case(0Xe0): KeyValue=KeyValue+12;break; } while((a<50)&&(GPIO_KEY!=0xf0)) { delay(1000); a++; } } } else { KeyValue=0xff; } return KeyValue; } //===========================分隔// /*/////////////下面這段聲明移到前面開頭的聲明 //#include <reg52.h> //typedef unsigned char uchar; //typedef unsigned int uint; //sbit LSA=P2^2; //sbit LSB=P2^3; //sbit LSC=P2^4; //uchar smg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, //0x7f,0x6f}; //////////////////////*/ void delay(uint a) { while(a--); } void dig_Disp() { uchar i=0; for(;i<8;i++) { switch(i) { case 0: LSA=0;LSB=0;LSC=0;P0=smg[0];break; case 1: LSA=1;LSB=0;LSC=0;P0=smg[1];break; case 2: LSA=0;LSB=1;LSC=0;P0=smg[2];break; case 3: LSA=1;LSB=1;LSC=0;P0=smg[1];break; case 4: LSA=0;LSB=0;LSC=1;P0=smg[9];break; case 5: LSA=1;LSB=0;LSC=1;P0=smg[1];break; case 6: LSA=0;LSB=1;LSC=1;P0=smg[0];break; case 7: LSA=1;LSB=1;LSC=1;P0=smg[2];break; } delay(100); P0=0x00; } } void main() { while(1) { //////////////移到這里,屏蔽多余的語句 //void main() //{ // Timer0Init(); // while(1) // { key_num=KeyDown(); if(key_num!=0xff) { Pinlv=Tab_F[key_num]; beep=1; Shichang=0; EA=1; } // }; // //} ///////////////////////////////// dig_Disp(); } } |
不清楚你放的這三個程序是什么關(guān)系,我也是初學(xué)的,不過大概看了一下好像找不到shuxian這個東東,報錯提示你的main里面沒有用到這個shuxian,還有那兩個重復(fù)定義的提示,建議還是先看清楚程序哪里漏了什么東西吧,慢慢找原因總能解決的 |
工程架構(gòu)不知道正確不,這個控制數(shù)碼管的程序一直實現(xiàn)不過 |
Powered by 單片機教程網(wǎng)