- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
}
}
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah and the port 0[0] is configurated:
Globalinputeven, High Z and interruptions disabled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
... and I miss the #pragma ioport declaration (have a look into the c-language manual)
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
... 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, you have to have debounce of the key first.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes,
it would be good to reuse the existing delay function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I have configured P0[0] as input pin and I want check the input status of P0[0] using #pragma ioport directive.
#pragma ioport Key_Input 0x01; char Key_Input;
if (Key_Input == 1)
{
/* Do something */
}
I want to know how do I guarantee that Im accessing P0[0]. The part number Im using is CY8C28452.
Thanks & Regards
Srinivas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would have been better to start a new thread to get help instead of using a three year old thread fom somebody else.
IOs are organized as ports of 8 bit width and are already declared as #pragma ioport. For each port there is a data register named PRTnDR where "n" is the port number. so to get P0[0] you may write
Key_Input = PRT0DR & 0x01; // Masking all bits except bit 0
To make the access easier you may define some macros as for instance
#define GetPortBit(Port,BitNo) (Port & /0x01 << BitNo))
and
#define Key_Input (GetPortBit(PRT0DR,0))
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the input pin is a mechanical switch/contact then you need to debounce the
pins input. See attached possible methods.
Additionally if you do read modify writes to the port you will need to use Shadow
Register -
http://www.cypress.com/?rID=2900 AN2094
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
Thanks for the reply.
I knew this approach, however I thought there could be some special keywords supported by compiler Image Craft to define bit variable pointing to particular pin of port. For ex sbit supported by keil.
However now I have realised that bit operations are the only way to perform read/write operation.
Thanks & Regards,
Srinivas