本帖最后由 丄帝De咗臂 于 2015-5-23 18:21 编辑
一、名称:简易手机(此品是我等当年在温州中学所做)二、功能:该简易手机初步实现了打电话、接电话、和挂电话的功能。
三、器材: LCD显示屏https://www.dfrobot.com.cn/goods-372.html 4*4 薄膜数字键盘https://www.dfrobot.com.cn/goods-431.html
GPS模块https://www.dfrobot.com.cn/goods-716.html
Arduino控制器
四、接线:
LCD显示屏:GND、VCC、A4和A5; GPS模块:连接Arduino,其中S1在comm端、S2在Arduino端、Uart Seclect在中间。 4*4薄膜数字键盘:接在数字口的6~13,其中D在数字口13。
五、程序代码:
- #include <Keypad.h>
- #include <Wire.h>
- #include <String.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,16,2);
- const byte ROWS = 4;
- const byte COLS = 4;
- char telNumber[81];
- int lenth=0;
- char callNumber[13];
- char ch=0;
- int i=0;
- int j=0;
- char hexaKeys[ROWS][COLS] = {
- {'1','2','3','A'},
- {'4','5','6','B'},
- {'7','8','9','C'},
- {'*','0','#','D'}
- };
- byte rowPins[ROWS] = {6,7,8,9};
- byte colPins[COLS] = {10,11,12,13};
- //initialize an instance of class NewKeypad
- Keypad customKeypad = Keypad(makeKeymap(hexaKeys),rowPins,colPins,ROWS,COLS);
- //remove buff dada
- void clearBuff(void)
- {
- for(j=0;j<81;j++)
- {
- telNumber[j]=0x00;
- }
- j=0;
- }
-
- void setup(){
- lcd.init(); // initialize the lcd
- lcd.backlight();
- pinMode(2,OUTPUT);
- pinMode(3,OUTPUT);
- pinMode(4,OUTPUT);
- pinMode(5,OUTPUT);
- //GSM开机时序
- digitalWrite(5,HIGH);
- delay(1500);
- digitalWrite(5,LOW);
- //使能GSM串口
- digitalWrite(3,LOW);
- digitalWrite(4,HIGH);
- delay(2000);
- //设置波特率
- Serial.begin(9600);
- //等待call ready
- delay(5000);
- delay(5000);
- delay(5000);
- digitalWrite(2,HIGH);
- delay(1000);
- // Serial.println("AT");
- lcd.clear();
- lcd.print("Welcome to:");
-
- }
- void loop()
- {
- char key=customKeypad.getKey();
- if(key!=NO_KEY)
- {
- delay(500);
- if(key!='*'&&key!='B')
- {
- telNumber[i++]=key;
- lcd.setCursor(0,3);
- lcd.print("call:");
- lcd.print(telNumber);
- }
- if(key=='*')//按*打电话
- {
- Serial.print("ATD");
- Serial.print(telNumber);
- Serial.println(";");
- Serial.flush();
- delay(1000);
- clearBuff();
- }
- else if(key=='#')
- {
- Serial.println("ATH\r\n");//按#挂电话
- lcd.setCursor(0,3);
- lcd.print("call:Hang up");
- delay(100);
- clearBuff();
- }
- else if(key=='B')
- {
- Serial.println("ATA\r\n");//按B挂电话
- lcd.setCursor(0,3);
- lcd.print("answer:ringing");
- Serial.flush();
- clearBuff();
- }
-
- }
- }
复制代码
六、使用方法:
1.将程序下载到控制器当中; 2.使用4*4 薄膜数字键盘作为拨号键盘; 3.打电话:在键盘上按下要拨的电话号码,然后按*键(LCD显示屏会显示拨出去的电话号码),电话即可拨出去; 4.接电话:按B键接听电话; 5.挂电话:按#键挂电话。
七、实物图:当时就留下一张,抱歉!
|
|
|
|
|
|