second is an integer, PrintXY expects a pointer to character (a string). You're creating a segfault. You have to use something like itoa to turn the number into a string. Pro-tip: When you see that reboot screen, just press [MENU]! No reboot required.
Code:
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
PrintXY(1, 1, second, 0, COLOR_BLACK);
GetKey(&key);
}
Should be...
Code:
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
GetKey(&key);
}
Why the strcpy? The first two characters of the string must be non-zero garbage characters (but they might have hidden uses). itoa :: IntegerTOArray and is defined in CONVERT_syscalls.h
- flyingfisch
- Minor Calculator Deity (Posts: 1088)
- 19 Apr 2012 10:26:12 am
- Last edited by flyingfisch on 19 Apr 2012 10:31:01 am; edited 2 times in total
KermMartian wrote:
second is an integer, PrintXY expects a pointer to character (a string). You're creating a segfault. You have to use something like itoa to turn the number into a string. Pro-tip: When you see that reboot screen, just press [MENU]! No reboot required.
Thank you for the tip!
One problem: itoa is included in stdlib.h, but prizmSDK doesn't use that. so is there a PrizmSDK-compatible function that converts integers to strings?
EDIT: never mind, ahelper ninja'd
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
I still get a reboot screen with this code:
Code:
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int main(void) {
int key;
int hour, minute, second, ms;
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, second, 0, COLOR_BLACK);
GetKey(&key);
}
return;
}
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
Code:
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
GetKey(&key);
}
You missed the change in PrintXY(1, 1, buffer, 0, COLOR_BLACK);
Ok, fixed.
Question: why do the numbers only refresh when I press a button other than [menu]?
Question: why do the numbers only refresh when I press a button other than [menu]?
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
GetKey is a blocking function. Look at the prizm wiki for how using PRGM_GetKey, which is nonblocking
Ahelper wrote:
Code:
strcpy(buffer," ");
Code:
buffer[0] = buffer[1] = ' ';
- flyingfisch
- Minor Calculator Deity (Posts: 1088)
- 19 Apr 2012 10:50:31 am
- Last edited by flyingfisch on 19 Apr 2012 11:05:48 am; edited 1 time in total
Ok, using this code freezes my calc at the menu screen...
Code:
WHY?!!!
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int PRGRM_Getkey(void);
int main(void) {
int key;
int hour, minute, second, ms;
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
PRGM_GetKey(&key);
switch(key) {
case KEY_PRGM_MENU:
break;
}
}
return;
}
int PRGM_GetKey(void) {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
WHY?!!!
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
KermMartian wrote:
Ahelper wrote:
Code:
strcpy(buffer," ");
Code:
buffer[0] = buffer[1] = ' ';
OK, I found out is was an incorrect prototype. And I think I am using PRGRM_GetKey incorrectly. If you guys could help me, that would be great
My code:
Code:
My error:
Code:
EDIT:
Ok, I changed my code:
Code:
but what happens is I get the pink and white loading symbol inthe corner of the main menu and I cannot get out of it. I thought that
Code:
would end the program when I pressed [MENU], but apparently it doesn't?
My code:
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int PRGM_GetKey(void);
int main(void) {
int key;
int hour, minute, second, ms;
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
PRGM_GetKey() = key;
switch(key) {
case KEY_PRGM_MENU:
break;
}
}
return 0;
}
int PRGM_GetKey(void) {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
My error:
Code:
flyingfisch@flyingfisch-Office-Computer:~/Desktop/PrizmSDK-0.3/projects/chess-timer$ make
/usr/local/cross/bin/sh3eb-elf-gcc -MMD -MP -MF /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/build/chess-timer.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib -I/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/build -I/home/flyingfisch/Desktop/PrizmSDK-0.3/include -std=c99 -c /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c -o chess-timer.o
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c: In function 'main':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:19:3: warning: pointer targets in passing argument 1 of 'RTC_GetTime' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/RTC_syscalls.h:4:6: note: expected 'unsigned int *' but argument is of type 'int *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:19:3: warning: pointer targets in passing argument 2 of 'RTC_GetTime' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/RTC_syscalls.h:4:6: note: expected 'unsigned int *' but argument is of type 'int *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:19:3: warning: pointer targets in passing argument 3 of 'RTC_GetTime' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/RTC_syscalls.h:4:6: note: expected 'unsigned int *' but argument is of type 'int *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:19:3: warning: pointer targets in passing argument 4 of 'RTC_GetTime' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/RTC_syscalls.h:4:6: note: expected 'unsigned int *' but argument is of type 'int *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:21:3: warning: implicit declaration of function 'strcpy' [-Wimplicit-function-declaration]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:21:3: warning: incompatible implicit declaration of built-in function 'strcpy' [enabled by default]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:22:3: warning: pointer targets in passing argument 2 of 'itoa' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/CONVERT_syscalls.h:6:6: note: expected 'unsigned char *' but argument is of type 'char *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:24:17: error: lvalue required as left operand of assignment
make[1]: *** [chess-timer.o] Error 1
make: *** [build] Error 2
EDIT:
Ok, I changed my code:
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int PRGM_GetKey(void);
int main(void) {
int key;
int hour, minute, second, ms;
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
key = PRGM_GetKey();
switch(key) {
case KEY_PRGM_MENU:
break;
}
}
return 0;
}
int PRGM_GetKey(void) {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
but what happens is I get the pink and white loading symbol inthe corner of the main menu and I cannot get out of it. I thought that
Code:
KEY_PRGM_MENU:
break;
would end the program when I pressed [MENU], but apparently it doesn't?
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
Eiyeron wrote:
PRGM_GetKey() = key;
Should be key= PRGM_GetKey()
Should be key= PRGM_GetKey()
Yes I know, look at my edited code
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
I don't think you think break means what it actually means. All that break does is break out of the switch/case statement to continue running code directly after the closing brace } closing the brace-pair that began at switch() {.
KermMartian wrote:
I don't think you think break means what it actually means. All that break does is break out of the switch/case statement to continue running code directly after the closing brace } closing the brace-pair that began at switch() {.
Yes, eiyeron helped me figure that out. Now here is my code:
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int PRGM_GetKey(void);
int main(void) {
int key;
int hour, minute, second, ms;
int done = 0;
while (!done) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
Bdisp_PutDisp_DD;
key = PRGM_GetKey();
if (key == KEY_PRGM_MENU) {
done = 1;
}
}
return 0;
}
int PRGM_GetKey(void) {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
It doesn't display anything though.
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
In addition to what Tari said, I have just a nitpicky thing: param 4 of PrintXY you have as '0', you should try using the actual definition, TEXT_MODE_NORMAL. And for param 5, you have "COLOR_BLACK", which you got luck on and is the same as "TEXT_COLOR_BLACK", however for the other colors if they start with "TEXT_COLOR" you should use them only with PrintXY's 5th argument, as they're 3 bit color defines; the ones that start with only "COLOR" are 16 bit defines, and besides "COLOR_BLACK" none of them will work for PrintXY.
Ashbad wrote:
In addition to what Tari said, I have just a nitpicky thing: param 4 of PrintXY you have as '0', you should try using the actual definition, TEXT_MODE_NORMAL. And for param 5, you have "COLOR_BLACK", which you got luck on and is the same as "TEXT_COLOR_BLACK", however for the other colors if they start with "TEXT_COLOR" you should use them only with PrintXY's 5th argument, as they're 3 bit color defines; the ones that start with only "COLOR" are 16 bit defines, and besides "COLOR_BLACK" none of them will work for PrintXY.
OK, thank you for telling me that. I didn't know there was a difference.
EDIT:
OK, i got all my code fixed, now I have another question.
The program displays the numbers 0-9, 16-25, 32-41, 48-57, 64-69, 80-90. Why doesn't it display the numbers 1-60?
And what does RTC_GetTicks() do?
Links to my calculator projects
I lurk #cemetech, if you want to contact me that and email are probably best.
I lurk #cemetech, if you want to contact me that and email are probably best.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
» Go to Registration page
» Go to Registration page
» Goto page Previous 1, 2, 3, 4, 5, 6 Next
» View previous topic :: View next topic
» View previous topic :: View next topic
Page 4 of 6
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Advertisement