Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > I need help

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



I need help
Moderator:
ARVI

Post Reply
Follow this topic



I need help

Clemen89 posted on 10 Nov 2011 7:49 AM PST
Member
6 Forum Posts

 

 Hi, I do not speak English very well, sorry :(.

I want that the display change when i press the button. I have got three menus for show in display. But when i press the buttom, the display dont change. I dont know where is the error.

My program in C:

 

----------------------------------------------------------------------------------------------

#include <m8c.h>        

#include "PSoCAPI.h"    

#include "Stdlib.h"

#include "m8c.h"

#include "math.h"

 

int cadena;

float datos;

int t;

int menu;

int aux;

 

void main(void)

{

 

    M8C_EnableGInt;

PGA_Start(PGA_HIGHPOWER);

ADCINC_Start(ADCINC_HIGHPOWER);

ADCINC_GetSamples(0);

Character_LCD_Start();               

       

while(1)

    //infinite loop.

{

if(menu==3){

menu=0;

}

switch(menu){

case 0:

if (ADCINC_fIsDataAvailable() != 0){    

if ((ADCINC_bGetData() <= 255)&&(ADCINC_bGetData() >0)){

AMUX4_1_InputSelect(AMUX4_1_PORT0_7); 

                datos=(float)ADCINC_wGetData()*5/255;

a=datos*100;

datos=floor(a);

datos=datos/100;

Character_LCD_Init();                           

for(t=0;t<50;t++){

Character_LCD_Position(1,2);               

Character_LCD_PrString(ftoa(datos,&cadena));

Character_LCD_Position(1,6);

Character_LCD_PrCString("      ");

Character_LCD_Position(1,12);

Character_LCD_PrCString("V");

Character_LCD_Position(0,1);

Character_LCD_PrCString("Selector 1:");

}

ADCINC_fClearFlag();                            

}

}

break;

case 1:

for(t=0;t<50;t++){

Character_LCD_Position(0,1);

Character_LCD_PrCString("Temperatura");

Character_LCD_Position(1,1);

Character_LCD_PrCString("Temperatura de referencia:");

}

ADCINC_fClearFlag();

break;

case 2:

for(t=0;t<50;t++){

Character_LCD_Position(0,1);

Character_LCD_PrCString("Configuracion:");

}

ADCINC_fClearFlag(); 

break;

}

aux=PRT0DR&&0x01;

if(aux!=0&&x==0){

menu=menu++;

x=1;

}else if(aux==0&&x==1){

x=0;

}

if(menu==3)menu=0;

}

}

---------------------------------------------------------------------------------------------
 
I am trying things with psoc for a asignature of university.  The program is very simple but I'm learning to use PSoC.
 
Is the PSoC 1.
 
Thanks!
 

 




Re: I need help

Clemen89 posted on 10 Nov 2011 07:51 AM PST
Member
6 Forum Posts

 Ah and the port 0[0] is configurated:

Globalinputeven, High Z and interruptions disabled.



Re: I need help

Bob Marlowe posted on 10 Nov 2011 02:25 PM PST
Top Contributor
1768 Forum Posts

Hi Clemen,

do not rely on a variable beeing initialized when you do not initialize it yourself.
You rely on menu equal to 0 (zero).

And it is better programmer's style to write

if (menu >= 3) menu = 0;

which in fact may help against some errors.

Have fun

Bob 



Re: I need help

Bob Marlowe posted on 10 Nov 2011 02:46 PM PST
Top Contributor
1768 Forum Posts

... and I miss the #pragma ioport declaration (have a look into the c-language manual)

Bob



Re: I need help

Bob Marlowe posted on 10 Nov 2011 02:52 PM PST
Top Contributor
1768 Forum Posts

... and another one (too much code to understand quickly)
It looks like you are using a pushbutton on port0[0]. so what is the port like, when the button is not pushed? Floating??

I use very often resistive output high, write a one to it and then read and debounce the pushbutton.

Bob



Re: I need help

H L posted on 10 Nov 2011 03:58 PM PST
Top Contributor
679 Forum Posts

Yes, you have to have debounce of the key first.



Re: I need help

H L posted on 10 Nov 2011 05:00 PM PST
Top Contributor
679 Forum Posts

Here is the modification I do

 

  aux=PRT0DR&&0x01;

  if(aux == 1)
  {
   /* only do this if x is 0*/
   if (x == 0)
   {
 
    /* add a delay here */
    /* Here is a quick but ugly way to do it */
    /* Add declare of i at the beginning of the code */
    /* you may need to experiment with the delay_count number */
    
    for(i = 0; i <= DELAY_COUNT; i ++);
   
    aux = PRT0DR && 0x01;
    
    /* only if it is still pressed */
    if(aux == 1)
    {
    
     if (++menu >= 3)
     {
      menu = 0;
     }
 
     x = 1;
    }
   }
  }
  else
  {
   x = 0;
  }



Re: I need help

kmmankad posted on 10 Nov 2011 08:02 PM PST
Top Contributor
268 Forum Posts

Rather than using a crude for loop for debounce delay,since youre already using an LCD,use the delay functions that it provides.

use LCD_Delay50uTimes(BYTE bTimes); where bTimes is the number of times to delay 50 μSec.

This is a clock independent delay.
 

PS:Hit 'Verify Answer' if my reply helped you.



Re: I need help

H L posted on 10 Nov 2011 08:54 PM PST
Top Contributor
679 Forum Posts

yes,

it would be good to reuse the existing delay function.



Re: I need help

Clemen89 posted on 11 Nov 2011 08:27 AM PST
Member
6 Forum Posts

Hi again!

Thank you very much to all!

The psoc is in the lab, on wednesday i will go to the lab and test all :)






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: KXP; Secondary Owner: VWA; Sunset Date: 01/01/20