总是报错,请问数组可不可以多次传递?
本帖最后由 butOn 于 2015-4-8 00:14 编辑问题出在prtpage函数上,难道要考虑数组退化?
/*
* OLED_Arduino-3.0.ino
*
* Created by Jack, April 5, 2015.
*
* FUNCTION: This is a driver program to display some pics or words
* on the OLED screen.
*
* OLED INFORMATION:
* 96` 128*64,
* driver chip: SSD1306,
*
* INTERFACE: 4-wire SPI.
*
*/
#define SDIN 9//D1
#define SCLK 10//D0
#define DC 11
#define RST 13
#define CS 12
typedef struct insert {
uint8_t page;
uint8_t start;
}insert;
insert in = {0, 0};
void OLED_INIT ();
void w_cmd (uint8_t c);
void w_data (uint8_t d);
void clear_display ();
void oprint (uint8_t w, insert *in);
void oled_printf (char text[]);
void prtpage (char c1[], char c2[], char c3[], char c4[]);
//ASCII-buff
uint8_t buff_0 = {
0xF0, 0xF8, 0x0C, 0xC4, 0x0C, 0xF8, 0xF0, 0x00,
0x03, 0x07, 0x0C, 0x08, 0x0C, 0x07, 0x03, 0x00
};
uint8_t buff_1 = {
0x00, 0x10, 0x18, 0xFC, 0xFC, 0x00, 0x00, 0x00,
0x00, 0x08, 0x08, 0x0F, 0x0F, 0x08, 0x08, 0x00
};
uint8_t buff_2 = {
0x08, 0x0C, 0x84, 0xC4, 0x64, 0x3C, 0x18, 0x00,
0x0E, 0x0F, 0x09, 0x08, 0x08, 0x0C, 0x0C, 0x00
};
uint8_t buff_3 = {
0x08, 0x0C, 0x44, 0x44, 0x44, 0xFC, 0xB8, 0x00,
0x04, 0x0C, 0x08, 0x08, 0x08, 0x0F, 0x07, 0x00
};
uint8_t buff_4 = {
0xC0, 0xE0, 0xB0, 0x98, 0xFC, 0xFC, 0x80, 0x00,
0x00, 0x00, 0x00, 0x08, 0x0F, 0x0F, 0x08, 0x00
};
uint8_t buff_5 = {
0x7C, 0x7C, 0x44, 0x44, 0x44, 0xC4, 0x84, 0x00,
0x04, 0x0C, 0x08, 0x08, 0x08, 0x0F, 0x07, 0x00
};
uint8_t buff_6 = {
0xF0, 0xF8, 0x4C, 0x44, 0x44, 0xC0, 0x80, 0x00,
0x07, 0x07, 0x08, 0x08, 0x08, 0x0F, 0x07, 0x00
};
uint8_t buff_7 = {
0x0C, 0x0C, 0x04, 0x84, 0xC4, 0x7C, 0x3C, 0x00,
0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00
};
uint8_t buff_8 = {
0xB8, 0xFC, 0x44, 0x44, 0x44, 0xFC, 0xB8, 0x00,
0x07, 0x0F, 0x08, 0x08, 0x08, 0x0F, 0x07, 0x00
};
uint8_t buff_9 = {
0x38, 0x7C, 0x44, 0x44, 0x44, 0xFC, 0xF8, 0x00,
0x00, 0x08, 0x08, 0x08, 0x0C, 0x07, 0x03, 0x00
};
uint8_t buff_a = {
0x00, 0xA0, 0xA0, 0xA0, 0xE0, 0xC0, 0x00, 0x00,
0x07, 0x0F, 0x08, 0x08, 0x07, 0x0F, 0x08, 0x00
};
uint8_t buff_b = {
0x04, 0xFC, 0xFC, 0x20, 0x60, 0xC0, 0x80, 0x00,
0x00, 0x0F, 0x0F, 0x08, 0x08, 0x0F, 0x07, 0x00
};
uint8_t buff_c = {
0xC0, 0xE0, 0x20, 0x20, 0x20, 0x60, 0x40, 0x00,
0x07, 0x0F, 0x08, 0x08, 0x08, 0x0C, 0x04, 0x00
};
uint8_t buff_d = {
0x80, 0xC0, 0x60, 0x24, 0xFC, 0xFC, 0x00, 0x00,
0x07, 0x0F, 0x08, 0x08, 0x07, 0x0F, 0x08, 0x00
};
uint8_t buff_e = {
0xC0, 0xE0, 0xA0, 0xA0, 0xA0, 0xE0, 0xC0, 0x00,
0x07, 0x0F, 0x08, 0x08, 0x08, 0x0C, 0x04, 0x00
};
uint8_t buff_f = {
0x40, 0xF8, 0xFC, 0x44, 0x0C, 0x18, 0x00, 0x00,
0x08, 0x0F, 0x0F, 0x08, 0x00, 0x00, 0x00, 0x00
};
uint8_t buff_g = {
0xC0, 0xE0, 0x20, 0x20, 0xC0, 0xE0, 0x20, 0x00,
0x27, 0x6F, 0x48, 0x48, 0x7F, 0x3F, 0x00, 0x00
};
uint8_t buff_h = {
0x04, 0xFC, 0xFC, 0x40, 0x20, 0xE0, 0xC0, 0x00,
0x08, 0x0F, 0x0F, 0x00, 0x00, 0x0F, 0x0F, 0x00
};
uint8_t buff_i = {
0x00, 0x00, 0x20, 0xEC, 0xEC, 0x00, 0x00, 0x00,
0x00, 0x00, 0x08, 0x0F, 0x0F, 0x08, 0x00, 0x00
};
uint8_t buff_j = {
0x00, 0x00, 0x00, 0x00, 0x20, 0xEC, 0xEC, 0x00,
0x00, 0x30, 0x70, 0x40, 0x40, 0x7F, 0x3F, 0x00
};
uint8_t buff_k = {
0x04, 0xFC, 0xFC, 0x80, 0xC0, 0x60, 0x20, 0x00,
0x08, 0x0F, 0x0F, 0x01, 0x03, 0x0E, 0x0C, 0x00
};
uint8_t buff_l = {
0x00, 0x00, 0x04, 0xFC, 0xFC, 0x00, 0x00, 0x00,
0x00, 0x00, 0x08, 0x0F, 0x0F, 0x08, 0x00, 0x00
};
uint8_t buff_m = {
0xE0, 0xE0, 0x60, 0xC0, 0x60, 0xE0, 0xC0, 0x00,
0x0F, 0x0F, 0x00, 0x07, 0x00, 0x0F, 0x0F, 0x00
};
uint8_t buff_n = {
0x20, 0xE0, 0xC0, 0x20, 0x20, 0xE0, 0xC0, 0x00,
0x00, 0x0F, 0x0F, 0x00, 0x00, 0x0F, 0x0F, 0x00
};
uint8_t buff_o = {
0xC0, 0xE0, 0x20, 0x20, 0x20, 0xE0, 0xC0, 0x00,
0x07, 0x0F, 0x08, 0x08, 0x08, 0x0F, 0x07, 0x00
};
uint8_t buff_p = {
0x20, 0xE0, 0xC0, 0x20, 0x20, 0xE0, 0xC0, 0x00,
0x40, 0x7F, 0x7F, 0x48, 0x08, 0x0F, 0x07, 0x00
};
uint8_t buff_q = {
0xC0, 0xE0, 0x20, 0x20, 0xC0, 0xE0, 0x20, 0x00,
0x07, 0x0F, 0x08, 0x48, 0x7F, 0x7F, 0x40, 0x00
};
uint8_t buff_r = {
0x20, 0xE0, 0xC0, 0x60, 0x20, 0xE0, 0xC0, 0x00,
0x08, 0x0F, 0x0F, 0x08, 0x00, 0x00, 0x00, 0x00
};
uint8_t buff_s = {
0x40, 0xE0, 0xA0, 0x20, 0x20, 0x60, 0x40, 0x00,
0x04, 0x0C, 0x09, 0x09, 0x0B, 0x0E, 0x04, 0x00
};
uint8_t buff_t = {
0x20, 0x20, 0xF8, 0xFC, 0x20, 0x20, 0x00, 0x00,
0x00, 0x00, 0x07, 0x0F, 0x08, 0x0C, 0x04, 0x00
};
uint8_t buff_u = {
0xE0, 0xE0, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00,
0x07, 0x0F, 0x08, 0x08, 0x07, 0x0F, 0x08, 0x00
};
uint8_t buff_v = {
0x00, 0xE0, 0xE0, 0x00, 0x00, 0xE0, 0xE0, 0x00,
0x00, 0x03, 0x07, 0x0C, 0x0C, 0x07, 0x03, 0x00
};
uint8_t buff_w = {
0xE0, 0xE0, 0x00, 0x80, 0x00, 0xE0, 0xE0, 0x00,
0x07, 0x0F, 0x0C, 0x07, 0x0C, 0x0F, 0x07, 0x00
};
uint8_t buff_x = {
0x20, 0x60, 0xC0, 0x80, 0xC0, 0x60, 0x20, 0x00,
0x08, 0x0C, 0x07, 0x03, 0x07, 0x0C, 0x08, 0x00
};
uint8_t buff_y = {
0xE0, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00,
0x47, 0x4F, 0x48, 0x48, 0x68, 0x3F, 0x1F, 0x00
};
uint8_t buff_z = {
0x60, 0x60, 0x20, 0xA0, 0xE0, 0x60, 0x20, 0x00,
0x0C, 0x0E, 0x0B, 0x09, 0x08, 0x0C, 0x0C, 0x00
};
void setup (){
OLED_INIT ();
clear_display ();//一切好像总是等待那里,指向着同样的事情...
}
void loop (){
//prtpage ("", " but0n", "", "");
//prtpage ("", " knowledge", " is", " power");
//prtpage (" qq", "", " 32700567", "");
//while (1){}
}
void OLED_INIT (){
pinMode (SDIN, OUTPUT);
pinMode (SCLK, OUTPUT);
pinMode (DC, OUTPUT);
pinMode (RST, OUTPUT);
pinMode (CS, OUTPUT);
// You can findInitial Sequence on the datasheet
digitalWrite (RST, HIGH);// Set RES# as High
delay (1); // 3us Delay Recommended
digitalWrite (RST, LOW);// Reset
delay(10);
digitalWrite (RST, HIGH);
w_cmd (0xAE);// 1.Set Display Off
w_cmd (0xD5); // 2.Set display Clock Divide Ratio/Oscillator Frequency
w_cmd (0x80);
w_cmd (0xA8); // 3.Set Multiplex Ratio
w_cmd (0x3F);
w_cmd (0xD3); // 4.Set Display Offset
w_cmd (0x00);
w_cmd (0x40); // 5.Set Display Start Line
// 6.Set Segment Re-Map 0xA1 ***
// 7.Set COM Output Scan Direction 0xC8 ***
// 8.Set COM Pins Hardware Configurartion 0xDA, 0x12 ***
// 9.Set Contrast Control 0x81, 0x66 **^
// 10.Set Pre-Charge Period 0xD9, 0xF1 ***
// 11.Set VCOMH Deselect Level 0xDB, 0x30 **^
// 12.Set Entire Display On/Off 0xA4 ***
// 13.Set Normal/Inverse Display 0xA6 ***
// Clear Screen
// w_cmd (0x8D);// 14.Set Charge Pump
// w_cmd (0x14);
// 15.Set Display On 0xAF ***
w_cmd (0x20);
w_cmd (0x10); //0x00
w_cmd (0xA1); // 6.Set Segment Re-Map
w_cmd (0xC8); // 7.Set COM Output Scan Direction
w_cmd (0xDA); // 8.Set COM Pins Hardware Configurartion
w_cmd (0x12);
w_cmd (0x81); // 9.Set Contrast Control 0x66
w_cmd (0x66); // 0xCF
w_cmd (0xD9); // 10.Set Pre-Charge Period
w_cmd (0xF1);
w_cmd (0xDB); // 11.Set VCOMH Deselect Level0x30
w_cmd (0x30); // 0x40
w_cmd (0xA4); // 12.Set Entire Display On/Off
w_cmd (0xA6); // 13.Set Normal/Inverse Display
w_cmd (0x8D);// 14.Set Charge Pump
w_cmd (0x14);
w_cmd (0xAF); // 15.Set Display On
}
void w_cmd (uint8_t c){
digitalWrite (CS, HIGH);
digitalWrite (DC, LOW); // Command
digitalWrite (CS, LOW);
shiftOut (SDIN, SCLK, MSBFIRST, c);
digitalWrite (CS, HIGH);
}
void w_data (uint8_t d){
digitalWrite (CS, HIGH);
digitalWrite (DC, HIGH); // Data
digitalWrite (CS, LOW);
shiftOut (SDIN, SCLK, MSBFIRST, d);
digitalWrite (CS, HIGH);
}
void clear_display (){
w_cmd (0xAE);
in = {0, 0};
uint8_t x, y; // x = SEG y = PAGE
for (y = 0; y < 8; y++){
w_cmd (0xB0 + y);// Set Page Number
w_cmd (0x00);//Set Low(4bit)
w_cmd (0x10);//Set High (4bit)
for (x = 0; x<128; x++)
w_data (0x00);
}
w_cmd (0xAF);
}
void oprint (uint8_t w, struct insert *in){
if (in->page > 7 ){
*in = {0, 0};
delay (500);
clear_display ();
}
uint8_t t, n;
for (t = 0; t < 2; t++){
w_cmd (0xB0 + in->page + t);
w_cmd (in->start & 0x0F);
w_cmd (((in->start >> 4) & 0x0F) | 0x10);
for (n = 0; n < 8; n++){
switch (w){
case '0':
w_data (buff_0);
break;
case '1':
w_data (buff_1);
break;
case '2':
w_data (buff_2);
break;
case '3':
w_data (buff_3);
break;
case '4':
w_data (buff_4);
break;
case '5':
w_data (buff_5);
break;
case '6':
w_data (buff_6);
break;
case '7':
w_data (buff_7);
break;
case '8':
w_data (buff_8);
break;
case '9':
w_data (buff_9);
break;
case 'a':
w_data (buff_a);
break;
case 'b':
w_data (buff_b);
break;
case 'c':
w_data (buff_c);
break;
case 'd':
w_data (buff_d);
break;
case 'e':
w_data (buff_e);
break;
case 'f':
w_data (buff_f);
break;
case 'g':
w_data (buff_g);
break;
case 'h':
w_data (buff_h);
break;
case 'i':
w_data (buff_i);
break;
case 'j':
w_data (buff_j);
break;
case 'k':
w_data (buff_k);
break;
case 'l':
w_data (buff_l);
break;
case 'm':
w_data (buff_m);
break;
case 'n':
w_data (buff_n);
break;
case 'o':
w_data (buff_o);
break;
case 'p':
w_data (buff_p);
break;
case 'q':
w_data (buff_q);
break;
case 'r':
w_data (buff_r);
break;
case 's':
w_data (buff_s);
break;
case 't':
w_data (buff_t);
break;
case 'u':
w_data (buff_u);
break;
case 'v':
w_data (buff_v);
break;
case 'w':
w_data (buff_w);
break;
case 'x':
w_data (buff_x);
break;
case 'y':
w_data (buff_y);
break;
case 'z':
w_data (buff_z);
break;
default:
case ' ':
w_data (0x00);
break;
}//switch
}//for
}
in->start += 8;
if (in->start >= 128){
in->start = 0;
in->page += 2;
}
}
void oled_printf(char text[]) {
int c, q;
for (c = 0; text != NULL; c++)
oprint (text, &in);
for (q = 0; q < (16 - c); q++)
oprint (' ', &in);
}
void prtpage (char c1[], char c2[], char c3[], char c4[]) {
w_cmd (0xAE);
oled_printf (c1[], &in);
oled_printf (c2[], &in);
oled_printf (c3[], &in);
oled_printf (c4[], &in);
w_cmd (0xAF);
delay (1200);
clear_display ();
delay (800);
}
声明是这个
void oled_printf(char text[]) {
int c, q;
for (c = 0; text != NULL; c++)
oprint (text, &in);
for (q = 0; q < (16 - c); q++)
oprint (' ', &in);
}
你确定这样调用没问题吗?
oled_printf (c1[], &in);
oled_printf (c2[], &in);
oled_printf (c3[], &in);
oled_printf (c4[], &in); 328522073 发表于 2015-4-7 14:39 static/image/common/back.gif
声明是这个
void oled_printf(char text[]) {
int c, q;
啊啊啊啊啊啊原来是酱紫 我要炸了了!!!!
谢谢! 328522073 发表于 2015-4-7 14:39 static/image/common/back.gif
声明是这个
void oled_printf(char text[]) {
int c, q;
还是不行,char* to char**、before ] 什么的,和数组有关 错误信息是什么? butOn 发表于 2015-4-7 18:30 static/image/common/back.gif
还是不行,char* to char**、before ] 什么的,和数组有关
声明是这个
void oled_printf(char text[]) {
int c, q;
for (c = 0; text != NULL; c++)
oprint (text, &in);
for (q = 0; q < (16 - c); q++)
oprint (' ', &in);
}
调用应该是oled_printf(c1),不再加方括号。数组名表示数组首地址指针。c1是char*型指针,c1[]表示指针的指针即char**。(oled_printf(char text[])表示接受的参数是oled_printf(char *)) 328522073 发表于 2015-4-7 22:43 static/image/common/back.gif
声明是这个
void oled_printf(char text[]) {
int c, q;
我后来试着删除了括号结果编译成功了
原来是这样, 谢谢
页:
[1]