高级会员
主题
帖子
积分3427
阅读权限30
注册时间2011-11-1
最后登录1970-1-1
在线时间 小时
|
一乐网店购买:2004字符型液晶显示 ATmega128主控 初步资料已发,这里再提供个测试程序:1 源程序:- /*
- LiquidCrystal Library - Hello World
- */
- // include the library code:
- #include <LiquidCrystal.h>
- #define BUTTON_NUM 6
- const int buttonPin[ BUTTON_NUM] = {4, 5, 6, 7, 8, 9 }; // the number of the pushbutton pin, SW1, SW2, SW3, SW4,SW5, SW6
- #define LED_NUM 3
- const int ledPin[LED_NUM] = {48, 47, 46}; // the number of the LED pin, LED1, LED2, LED3
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(49, 51, 50,61,60,59,58,57, 56, 55, 54); //
- void setup() {
- // set up the LCD's number of columns and rows:
- Serial1.begin(9600);
- lcd.begin(20, 4);
- // Print a message to the LCD.
- lcd.print("hello, world!");
- lcd.setCursor(0, 2);
- lcd.print("by huaweiwx 2015");
- lcd.setCursor(0, 3);
- lcd.print("bbs.yleee.com.cn");
- for (int i = 0; i < LED_NUM; i++)
- pinMode(ledPin[i], 1);
- Serial1.println("hello world");
- }
- void loop() {
- int buttonState = 0;
- for (int i = 0; i < BUTTON_NUM; i++)
- {
- buttonState = ((digitalRead(buttonPin[i]) ==0)?1:0);
- switch (i)
- {
- case 0:
- lcd.setCursor(14, 1);
- lcd.print(buttonState);
- break;
- case 1:
- lcd.setCursor(15, 1);
- lcd.print(buttonState);
- if (buttonState) digitalToggle(ledPin[0]);
- break;
- case 2:
- lcd.setCursor(16, 1);
- lcd.print(buttonState);
- break;
- case 3:
- lcd.setCursor(17, 1);
- lcd.print(buttonState);
- if (buttonState)digitalToggle(ledPin[1]);
- break;
- case 4:
- lcd.setCursor(18,1);
- lcd.print(buttonState);
- break;
- case 5:
- lcd.setCursor(19, 1);
- lcd.print(buttonState);
- if (buttonState)digitalToggle(ledPin[2]);
- break;
- }
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- lcd.setCursor(0, 1);
- // print the number of seconds since reset:
- lcd.print(millis() / 1000);
- // line2
- }
- delay(500);
- }
复制代码 2 下载包:
lcd2004HelloWorld.rar
(24.96 KB, 下载次数: 101)
包括上述代码编译完成的hex、elf和源代码,对于没有安装arduino的朋友直接将其中hex下载,elf文件可在proteus中模拟运行和调试,其中lcd2004HelloWorld.ino是上述源程序。
3 说明,如再arduinozion中重新编译,或以此修改开发,请 将 zion中board.txt 中频率改为 11059200,还要对上述 buttonPin[ BUTTON_NUM] = {4, 5, 6, 7, 8, 9 }、LEDPin[LED_NUM] = {48, 47, 46}、LiquidCrystal lcd(49, 51, 50,61,60,59,58,57, 56, 55, 54); 中的编号改为对应zion的脚号定义;我用的是自己的一个定义,我将其称为自然表示法,arduino脚号对应于芯片脚号,在proteus中调试一目了然,而zion等的奇怪编号方式我不喜欢。我也懒惰给大家改了,如有问题,可以咨询我。
另外,程序中有个函数 digitalToggle(pin),这不是arduino的标准函数,是我自定义的函数,功能是转换led灯亮灭状态,你需要自己增加这个函数。
测试功能:
1 开机时会在rs232串口显示:hello world! 同时在lcd显示屏上显示信息;
2 lcd 显示一个一秒增加1 的计数值,显示开机的秒数。
3 lcd显示6个按钮的状态,按下显示1 否则显示0;
4 其中 2 4 6 按钮按下,led 显示状态会转换;
|
|