[Fireduino试用体验] 实验一 开发平台和测试驱显-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5316|回复: 0

[Fireduino试用体验] 实验一 开发平台和测试驱显

[复制链接]
发表于 2017-4-17 17:44 | 显示全部楼层 |阅读模式
[Fireduino试用体验] 实验一 开发平台和测试驱显
开发平台的创建着实费了不少功夫,下载所有说明、资料、开发软件等而后学习了一下,感觉差不多了直接展开Arduino1.6.8这款开发软件,感觉以前玩过328芯片应该没有问题,就直接上以前编译通过了的LCD0713黑白显示屏,结果发现问题多多。按照其他开发板的经验,连接上USB应该出现什么未知设备之类的警告,余下的就是八仙过海了,结果什么都没有发生——自认为,此USB就是供电用的,于是按照以前的方法,招了一个AVRAsp下载器按照图示连接好线,结果他根本不认这个下载器,报错为:Upgrade failed:No found any rockusb device,please plug device in!就是说,这个开发板需要rockusb device设备下载,但无论怎么操作死活没有这么个设备出现,于是马上在“Firefly小分队”发帖求助,很不错,这个聊天群很棒很快就有了响应,按照网友的帖子,我是从安全模式安装的驱动——安全模式是最简单好用的,并且支持所有无法安装驱动的终极手段。回到正常模式之后,插上USB线,还是没有出现?!于是尝试着重新按Reset和UpGrade两个键,松开手后设备出现了,但有个小问号,没有理会,直接下载程序,一切Ok。无意间看设备管理器,哪个rockusb device有没有了?!经过多次实验,得出的结果是下载时双按两个键,出现rockusb device下载,按Reset键运行程序后,哪个rockusb device就有隐退了——真是短命皇帝。不过不影响编程下载就可以了。不知你们也是这样吗?见照片10,11。
下边开始编程,以前做过LCD0713的程序,直接拿来,为了省事,写了一个0713.h的函数放在主函数的文件夹中,代码如下:
#include <arduino.h>
//define IO for LCD0713
#define dat 8
#define clk 9
#define res 10
#define reg 11
//KS0713 LCD
const unsigned char asc2[][6]={//8x6
{0x00,0x3E,0x45,0x49,0x51,0x3E},//0
{0x00,0x00,0x21,0x7F,0x01,0x00},//1
{0x00,0x31,0x43,0x45,0x49,0x31},//2
{0x00,0x22,0x49,0x49,0x49,0x36},//3
{0x00,0x04,0x0C,0x14,0x7F,0x04},//4
{0x00,0x72,0x51,0x51,0x51,0x4E},//5-5
{0x00,0x3E,0x49,0x49,0x49,0x06},//6
{0x00,0x40,0x43,0x4C,0x50,0x60},//7
{0x00,0x36,0x49,0x49,0x49,0x36},//8
{0x00,0x30,0x48,0x48,0x48,0x3F},//9
{0x00,0x1F,0x24,0x64,0x24,0x1F},//A-10
{0x00,0x41,0x7F,0x49,0x49,0x36},//B
{0x00,0x3E,0x41,0x41,0x41,0x22},//C
{0x00,0x41,0x7F,0x41,0x41,0x3E},//D
{0x00,0x41,0x7F,0x49,0x49,0x63},//E
{0x00,0x41,0x7F,0x49,0x5C,0x60},//F-15
{0x00,0x3E,0x41,0x45,0x47,0x24},//G
{0x41,0x7F,0x08,0x08,0x08,0x7F},//H
{0x00,0x00,0x41,0x7F,0x41,0x00},//I
{0x00,0x42,0x41,0x7F,0x40,0x40},//J
{0x00,0x41,0x7F,0x59,0x24,0x43},//K-20
{0x00,0x40,0x7F,0x41,0x01,0x03},//L
{0x00,0x7F,0x20,0x1E,0x20,0x7F},//M
{0x00,0x7F,0x30,0x18,0x06,0x7F},//N
{0x00,0x3E,0x41,0x41,0x41,0x3E},//O
{0x00,0x41,0x7F,0x49,0x48,0x30},//P-25
{0x00,0x3E,0x41,0x47,0x42,0x3D},//Q
{0x00,0x41,0x7F,0x49,0x4C,0x33},//R
{0x00,0x32,0x49,0x49,0x49,0x26},//S
{0x00,0x60,0x41,0x7F,0x41,0x60},//T
{0x00,0x7E,0x01,0x01,0x01,0x7E},//U-30
{0x00,0x7C,0x02,0x01,0x02,0x7C},//V
{0x00,0x7C,0x03,0x3C,0x03,0x7C},//W
{0x00,0x43,0x24,0x18,0x24,0x43},//X
{0x00,0x60,0x18,0x07,0x18,0x60},//Y
{0x00,0x63,0x45,0x49,0x51,0x63},//Z-35
{0x00,0x00,0x00,0x01,0x00,0x00},//.
{0x00,0x14,0x14,0x14,0x14,0x14},//=
{0x00,0x08,0x08,0x3E,0x08,0x08},//+
{0x00,0x08,0x08,0x08,0x08,0x08},//-
{0x00,0x00,0x00,0x24,0x00,0x00},//:-40
};
//Write Plus
void wri(){
digitalWrite(clk,LOW);
digitalWrite(clk,HIGH);
}
//Write 1 byte to LCD,dtata,Command:1/0-Data
void b2l(unsigned int dt,unsigned int com){
unsigned int i;
if(com) digitalWrite(reg,HIGH);else digitalWrite(reg,LOW);
for(i=0;i<8;i++){
  if(dt&0x80) digitalWrite(dat,HIGH);else digitalWrite(dat,LOW);
  dt=dt<<1;
  wri();
}
}
//Set LCD X:0-102 Y:0-3
void setXY(unsigned int pag,unsigned int col){
b2l(0xB0+pag,0);//page
col+=0x04;//+4-->4bit
b2l(0x10+((col&0xF0)>>4),0);//0x12
b2l(col&0x0F,0);//row-L4
}
//LCD Clear
void lcdClear(void){
unsigned int pag,col;
for(pag=0;pag<8;pag++){
  setXY(pag,0);
  for(col=0;col<132;col++){b2l(0x00,1);};
}
}
//c:Char,cha[]
void c2l(unsigned int pag,unsigned int col,unsigned int c){
unsigned int line;
setXY(pag,col*6);
for (line=0;line<6;line++)
b2l(asc2[c][line],1);
}
//KS0713LCD Initial
void lcdInit(void){
digitalWrite(res,LOW);
delay(100);
digitalWrite(res,HIGH);
delay(100);
b2l(0xAE,0);
b2l(0xE2,0);
b2l(0xA1,0);
b2l(0xC8,0);
b2l(0xA2,0);
b2l(0x2F,0);
delay(20);
b2l(0x23,0);
delay(20);
b2l(0x81,0);
b2l(0x2C,0);
delay(20);
b2l(0xAD,0);
b2l(0x00,0);
b2l(0xAF,0);
delay(100);
}
主函数名lcd0713.ino,代码如下:
#include "lcd0713.h"

//define IO for LCD0713
#define led0 13

//define Avr for Test
long js,val1,val0;
int dut0,dut1,duty,ddt0=1,ddt1=2,pwmdir0,pwmdir1;
float dis;

//Display BaseData
void dispBase(void){
c2l(3,0,19);c2l(3,1,28);//JS
c2l(2,0,10);c2l(2,1,0);c2l(2,9,10);c2l(2,10,1);//A0 A1
c2l(1,0,25);c2l(1,1,32);c2l(1,2,22);c2l(1,8,25);c2l(1,9,32);c2l(1,10,22);//PWM PWM
c2l(0,0,13);c2l(0,1,18);c2l(0,2,28);//DIS
}
//Display Test Data
void dispMes(void){
c2l(3,3,(js/100000)%10);c2l(3,4,(js/10000)%10);c2l(3,5,(js/1000)%10);c2l(3,6,(js/100)%10);c2l(3,7,(js/10)%10);c2l(3,8,(js)%10);
c2l(2,3,(val0/1000)%10);c2l(2,4,(val0/100)%10);c2l(2,5,(val0/10)%10);c2l(2,6,(val0)%10);
c2l(2,11,(val1/1000)%10);c2l(2,12,(val1/100)%10);c2l(2,13,(val1/10)%10);c2l(2,14,(val1)%10);
c2l(1,4,(dut0/100)%10);c2l(1,5,(dut0/10)%10);c2l(1,6,(dut0)%10);
c2l(1,12,(dut1/100)%10);c2l(1,13,(dut1/10)%10);c2l(1,14,(dut1)%10);
c2l(0,4,int(dis/100)%10);c2l(0,5,int(dis/10)%10);c2l(0,6,int(dis)%10);c2l(0,7,36);c2l(0,8,int(dis*10)%10);c2l(0,9,int(dis*100)%10);
}
void setup(){
int i;
for(i=6;i<13;i++){pinMode(i,OUTPUT);}
lcdInit();
lcdClear();
dispBase();
}
void loop(){
digitalWrite(led0,LOW);
js++;
val0=analogRead(0);
val1=analogRead(1);
Serial.print("AD0=");Serial.println(val0);
Serial.print("AD1=");Serial.println(val1);
dispMes();
delay(50);
digitalWrite(led0,HIGH);
delay(50);
}
上述代码可以实现1路程序计数器、2路ADC,已设置、2路PWM、为了省事先删除了、还有1路测试超声传感器测距的,也删除了。结果见照片12。
结论:除了下载时需要双按键出现Rockusb之外,其他的还可以。只要能采用Arduino的方法来编程就是简单易上手。以后的就可以抽空实验了。

12

12

11

11

10

10
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 01:45 , Processed in 0.135355 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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