一乐电子

一乐电子百科

 找回密码
 请使用微信账号登录和注册会员

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 2809|回复: 14
收起左侧

[avr] 一乐网店购买:2004字符型液晶显示 ATmega128主控 测试程序

[复制链接]
发表于 2015-9-10 15:05 | 显示全部楼层 |阅读模式
一乐网店购买:2004字符型液晶显示 ATmega128主控 初步资料已发,这里再提供个测试程序:1 源程序
  1. /*
  2.   LiquidCrystal Library - Hello World
  3. */

  4. // include the library code:
  5. #include <LiquidCrystal.h>
  6. #define BUTTON_NUM 6
  7. const int buttonPin[ BUTTON_NUM] = {4, 5, 6, 7, 8, 9 }; // the number of the pushbutton pin,  SW1, SW2, SW3, SW4,SW5, SW6
  8. #define LED_NUM 3
  9. const int ledPin[LED_NUM]    = {48, 47, 46};   // the number of the LED pin, LED1, LED2, LED3
  10. // initialize the library with the numbers of the interface pins
  11. LiquidCrystal lcd(49, 51, 50,61,60,59,58,57, 56, 55, 54); //

  12. void setup() {
  13.   // set up the LCD's number of columns and rows:
  14.   Serial1.begin(9600);
  15.   lcd.begin(20, 4);
  16.   // Print a message to the LCD.
  17.   lcd.print("hello, world!");
  18.   lcd.setCursor(0, 2);
  19.   lcd.print("by huaweiwx 2015");
  20.   lcd.setCursor(0, 3);
  21.   lcd.print("bbs.yleee.com.cn");
  22.   for (int i = 0; i < LED_NUM; i++)
  23.     pinMode(ledPin[i], 1);
  24.   Serial1.println("hello world");  
  25. }

  26. void loop() {
  27.   int buttonState = 0;
  28.   for (int i = 0; i < BUTTON_NUM; i++)
  29.   {
  30.     buttonState = ((digitalRead(buttonPin[i]) ==0)?1:0);
  31.     switch (i)
  32.     {
  33.       case 0:
  34.       lcd.setCursor(14, 1);
  35.       lcd.print(buttonState);
  36.       break;
  37.       case 1:
  38.       lcd.setCursor(15, 1);
  39.       lcd.print(buttonState);
  40.        if (buttonState) digitalToggle(ledPin[0]);
  41.         break;
  42.       case 2:
  43.       lcd.setCursor(16, 1);
  44.       lcd.print(buttonState);
  45.       break;
  46.       case 3:
  47.         lcd.setCursor(17, 1);
  48.         lcd.print(buttonState);
  49.         if (buttonState)digitalToggle(ledPin[1]);
  50.         break;
  51.       case 4:
  52.        lcd.setCursor(18,1);
  53.        lcd.print(buttonState);
  54.       break;
  55.      case 5:
  56.      lcd.setCursor(19, 1);
  57.       lcd.print(buttonState);
  58.         if (buttonState)digitalToggle(ledPin[2]);
  59.         break;
  60.     }
  61.     // set the cursor to column 0, line 1
  62.     // (note: line 1 is the second row, since counting begins with 0):
  63.     lcd.setCursor(0, 1);
  64.     // print the number of seconds since reset:
  65.     lcd.print(millis() / 1000);
  66.     //  line2
  67.   }
  68.   delay(500);
  69. }
复制代码
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 显示状态会转换;


发表于 2015-9-11 10:30 | 显示全部楼层
谢谢楼主的无私奉献,我也买了两片,有空可以玩玩了
 楼主| 发表于 2015-9-12 23:39 | 显示全部楼层
没有买这个研究品的朋友,可以下载我提供proteus 模型模拟运行一下。
https://www.yleee.com.cn/thread-45221-1-1.html
发表于 2015-9-16 14:21 | 显示全部楼层
我也買了一套, 哪裡可以找到 Arduinozion 的 bootloader ?
 楼主| 发表于 2015-9-17 00:41 | 显示全部楼层
ani 发表于 2015-9-16 14:21
我也買了一套, 哪裡可以找到 Arduinozion 的 bootloader ?

这里我提供一个,不过我没亲测,因为我不用bootload,而是直接用usbasp来烧写:
ATmegaBOOT_168.rar (9.69 KB, 下载次数: 77)
修改上述包内的make文件,设置好芯片型号和晶振频率,生成即可。
发表于 2015-9-17 00:56 | 显示全部楼层
huaweiwx 发表于 2015-9-17 00:41
这里我提供一个,不过我没亲测,因为我不用bootload,而是直接用usbasp来烧写:

修改上述包内的make文 ...

謝謝, 我先試試

发表于 2015-9-17 10:27 | 显示全部楼层
谢谢楼主的无私奉献,
发表于 2015-10-17 17:10 | 显示全部楼层
楼主如果不做任何修改直接USBASP链接那个10针口可以下载程序吗

我试了下好像不能联机。下载线插到实验板连at89s52正常
听说把本站有此功能,为了支持站长,求打赏,哈哈
 楼主| 发表于 2015-10-17 17:12 | 显示全部楼层
USBASP,直接插上,可以联机的。
 楼主| 发表于 2015-10-17 17:15 | 显示全部楼层
yjfxue 发表于 2015-10-17 17:10
楼主如果不做任何修改直接USBASP链接那个10针口可以下载程序吗

我试了下好像不能联机。下载线插到实验 ...

你试一下接其他avr板子,可验证是否是isp和烧写软件的问题。还有你要用 progisp等烧录软件来烧写,这和51不同。

本版积分规则

QQ|一淘宝店|手机版|商店|电子DIY套件|一乐电子 ( 粤ICP备09076165号 ) 公安备案粤公网安备 44522102000183号

GMT+8, 2024-5-12 00:45 , Processed in 0.068585 second(s), 50 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表