8 years, 6 months ago.

help error

When i compile this program there is no error and i download the flie .bin correctcly, but when i try to send the string to microcontroller, the program crashes.

Any help would be greatly appreciated. Thanks in advance.

I post here the code:

  1. include "mbed.h"
  2. include "uLCD_4D_Picaso.h"
  3. include <iostream>

/**

  • Demo program for uLCD_4D_Picaso resistance touchscreen
  • Simple Graphing Application on resistive touchscreen display
  • @version 1.0
  • @author Andrew McRae, Tianhao Li
  • / three pins are: TX RX RESET uLCD_4D_Picaso Display(p13, p14, p15);

int frame = 0; int disk; uint16_t hndl1; uint16_t hndl2; int iUserimages1 = 0, iUserimages2 = 1, iUserimages3 = 2, iUserimages4 = 3, iUserimages5 = 4 int iImage1_1 = 0, iImage2_1 = 1, iImage3_1 = 2, iImage4_1 = 3, iImage5_1 = 4, iImage6_1 = 5, iImage7_1 = 6, iImage8_1 = 7, iImage9_1 = 8; int iImage1_2 = 0, iImage2_2 = 1, iImage3_2 = 2,iImage4_2 = 3, iImage5_2 = 4, iImage6_2 = 5, iImage7_2 = 6, iImage8_2 = 7, iImage9_2 = 8, iImage10_2 = 9, iImage11_2 = 10;

  1. define bufferlength 10

Serial pc(USBTX, USBRX); tx, rx

DigitalOut myled(LED1);

DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4);

char buffer[bufferlength]; int buffer_index=0; int loop=1;

This function is called when a character goes into the TX buffer. void txCallback() { led2 = !led2; }

This function is called when a character goes into the RX buffer. void rxCallback() { led3 = !led3; buffer[buffer_index] = pc.getc(); buffer_index++; if (buffer_index >= bufferlength) buffer_index = 0; }

int Eco(char Comand, float vel) { return Comand; }

struct phoneme{ char poss_ph[4][4]; int lips; };

void english_ph(phoneme vect_ph[20]) { Fonema 1 vect_ph[0].poss_ph[0][0]='a'; vect_ph[0].poss_ph[1][0]='i'; vect_ph[0].poss_ph[2][0]='y'; vect_ph[0].lips=1;

Fonema 2 vect_ph[1].poss_ph[0][0]='b'; vect_ph[1].poss_ph[1][0]='m'; vect_ph[1].poss_ph[2][0]='p'; vect_ph[1].lips=2;

Fonema 3 vect_ph[2].poss_ph[0][0]='c'; vect_ph[2].poss_ph[1][0]='e'; vect_ph[2].poss_ph[2][0]='g'; vect_ph[2].poss_ph[3][0]='t'; vect_ph[2].poss_ph[3][1]='h'; vect_ph[2].lips=3;

Fonema 4 vect_ph[3].poss_ph[0][0]='d'; vect_ph[3].poss_ph[1][0]='t'; vect_ph[3].poss_ph[2][0]='v'; vect_ph[3].poss_ph[3][0]='w'; vect_ph[3].lips=4;

Fonema 5 vect_ph[4].poss_ph[0][0]='f'; vect_ph[4].poss_ph[1][0]='n'; vect_ph[4].lips=5;

Fonema 6 vect_ph[5].poss_ph[0][0]='h'; vect_ph[5].poss_ph[1][0]='o'; vect_ph[5].poss_ph[2][0]='u'; vect_ph[5].lips=6;

Fonema 7 vect_ph[6].poss_ph[0][0]='l'; vect_ph[6].poss_ph[1][0]='r'; vect_ph[6].lips=7;

Fonema 8 vect_ph[7].poss_ph[0][0]='q'; vect_ph[7].poss_ph[1][0]='u'; vect_ph[7].poss_ph[2][0]='u'; vect_ph[7].poss_ph[2][1]='e'; vect_ph[7].lips=8;

Fonema 9 vect_ph[8].poss_ph[0][0]='s'; vect_ph[8].poss_ph[1][0]='z'; vect_ph[8].lips=9;

Fonema 10 vect_ph[9].poss_ph[0][0]='w'; vect_ph[9].poss_ph[0][1]='h'; vect_ph[9].lips=10;

Fonema 11 vect_ph[10].poss_ph[0][0]=' '; vect_ph[10].lips=11;

return; }

void control (char stringa[2000], phoneme vect_ph[20], int seq_ph[2000]) { int i=0; bool ok3=false, ok2=false, ok1=false; char temp[4]; for (int q=0; q<4; q++) temp[q]='\0'; int index_seq=0;

while (stringa[i]!='\0') { if (ok3==false && i<1997) controllo sillabe da 3 { for (int j=0; j<3; j++) { temp[j]=stringa[j+i]; } for (int k=0; k<20 && ok3==false; k++) { for (int h=0; h<4 && ok3==false; h++) { if (temp[0]==vect_ph[k].poss_ph[h][0]) if (temp[1]==vect_ph[k].poss_ph[h][1]) if (temp[2]==vect_ph[k].poss_ph[h][2]) { ok3=true; seq_ph[index_seq]=vect_ph[k].lips; index_seq++; i=i+2; } } } } if (ok3==false && ok2==false && i<1998) controllo sillabe da 2 { for (int j=0; j<2; j++) { temp[j]=stringa[j+i]; } for (int k=0; k<20 && ok2==false; k++) { for (int h=0; h<4 && ok2==false; h++) { if (temp[0]==vect_ph[k].poss_ph[h][0]) if (temp[1]==vect_ph[k].poss_ph[h][1]) { ok2=true; seq_ph[index_seq]=vect_ph[k].lips; index_seq++; i=i+2; } } } } if (ok3==false && ok2==false && ok1==false && i<1999) controllo sillabe da 1 { temp[0]=stringa[i]; for (int k=0; k<20 && ok1==false; k++) { for (int h=0; h<4 && ok1==false; h++) { if (temp[0]==vect_ph[k].poss_ph[h][0]) { ok1=true; seq_ph[index_seq]=vect_ph[k].lips; index_seq++; i=i+1; } } } } ok3=false; ok2=false; ok1=false; }

return; }

int main() {

/*Display.setbaudWait(Picaso::BAUD_600000); Display.touch_Set(0); Display.txt_Opacity(Picaso::OPAQUE); Display.gfx_RectangleFilled(200, 0, 230, 30, Picaso::WHITE); Display.gfx_RectangleFilled(0, 0, 30, 30, Picaso::WHITE); Display.txt_MoveCursor(1, 1); Display.putCH('E');

wait(0.200);*/

Display.gfx_ScreenMode(Picaso::LANDSCAPE);

uSD card mount routine Display.putStr("Mounting...\n"); print a string disk = Display.file_Mount(); if(disk==0) { while(disk==0) { Display.putStr("Drive not mounted... %i" ); wait(0.200); Display.gfx_Cls(); wait(0.200); disk = Display.file_Mount(); } }

Display.gfx_BGcolour(Picaso::WHITE ) ; change background color to white Display.gfx_Cls(); clear the screen

load the graphics files hndl = Display.file_LoadImageControl("USER_I1.dat", "USER_I1.gci", 1); hndl1 = Display.file_LoadImageControl("NoName2.dat", "NoName2.gci", 1); hndl2 = Display.file_LoadImageControl("NoName1.dat", "NoName1.gci", 1);

Display.img_Show(hndl,iImage1) ; show the penguin Display.gfx_Set(Picaso::TRANSPARENCY, 1); turn on transparency Display.gfx_Set(Picaso::TRANSPARENT_COLOUR, 0x3000); make this color transparent

wait(3);

pc.baud(115200);

pc.printf("\nINIT \n");

pc.attach(&rxCallback, Serial::RxIrq);

pc.printf("\nstart \n");

for(int i=0; i<bufferlength; i++) buffer[i]=255;

char Comand = 0 ; char Value = 0 ;

loop=1; while (loop){

if (buffer_index>1) { led1 = 1; pc.printf("\n errore sync \n"); pc.putc('e'); }

if (buffer_index>3) { buffer_index=0; led1 = 1; pc.putc('e'); pc.printf("\n errore reg full \n"); }

if (buffer[0] != 255) comando { pc.printf("\nComando ricevuto %c \n", buffer[0] ); Comand = buffer[0]; buffer_index=0; buffer[0]=255;

switch (Comand) { case 'a':

pc.printf("\nControl SET on \n");

break; on off

case 's':

pc.printf("\nControl SET off \n");

break; set lim

case 'd': pc.printf("\nControl SET remote control \n"); break; set lim

case 'f': Eco(Comand,Value); pc.printf("\nControl reset remote control \n"); break; set lim

case 'g': Display.img_Show(hndl2,10);

phoneme vect_ph[20];

for (int i=0; i<20; i++) { for (int j=0; j<4; j++) for (int k=0; k<4; k++) { vect_ph[i].poss_ph[j][k]='\0'; } vect_ph[i].lips=0; }

english_ph(vect_ph);

char stringa[2000]; int seq_ph[2000];

for (int i=0; i<2000; i++) { stringa[i]=255; seq_ph[i]=0; }

cout<<"Inserisci stringa: \n"; cin.getline(stringa,2000);

control (stringa,vect_ph,seq_ph);

for (int i=0; i<2000 && seq_ph[i]!=0; i++) { Display.img_Show(hndl2,seq_ph[i]-1); wait(0.3); }

break;

case 'z': Display.img_Show(hndl1,iImage4_1) ;

wait(0.5); break;

case 'x': Display.img_Show(hndl1,iImage5_1) ;

wait(3); break;

case 'c': Display.img_Show(hndl1,iImage6_1) ;

wait(3); wait(Pippo); break;

case 'v': Display.img_Show(hndl1,iImage7_1) ;

wait(3); break;

case 'b': Display.img_Show(hndl1,iImage8_1) ;

wait(3); break;

case 'n': Display.img_Show(hndl1,iImage9_1) ;

wait(3);

break;

case 'q': loop=0; break; } }

buffer_index = 0; buffer[0]=255;

wait(0.5);

}

pc.printf("STOP!\n");

}

Be the first to answer this question.