Stopwatch applicatie op ARm MCB2300

Status
Niet open voor verdere reacties.

DesertFox

Gebruiker
Lid geworden
11 mei 2013
Berichten
5
Ik moet de volgende applicatie maken:

Write the software for a stopwatch application. The stopwatch measures the time in hours, minutes, seconds and one hundreds of seconds. The functionality is defined as follows:
- The stopwatch shows the running time on the upper line of the display. The lap time is shown on the lower line of the lcd-module.
- On start, the stopwatch is in its reset-state. In the reset-state, the time and lap-time are both 00:00:00:00. The time is not running in the reset-state.
- The stopwatch goes from the reset-state to the run-state when switch int0 is pressed. In the run state, the time starts running. The running time is shown on the upper line of the display.
- When int0 is pressed while the time is in the run-state, the following happens:
a) The time at which int0 was pressed is shown at the upper line of the display for two seconds. After two seconds, the actual time is shown again on the upper line of the display (remark: the actual time keeps on running).
b) On the lower line, the lap time is shown. The lap time is defined as the time-interval between the last two successive presses on int0.
- The stopwatch goes from the run-state to the stop-state if int0 is pressed for longer than 1 second.
In the stop-state the time running stops and values shown on the display don’t change anymore. - The stopwatch goes from the stop-state to the reset-state by pressing int0.

Ik heb de volgende code gemaakt:
Code:
/* ******************** Workshop 1 -- Exercise 2 **************************/  
#include <stdio.h>  	 	   // standard C definitions 
#include "MCB2300 evaluationboard.h" // hardware related functions 
#include "LCD.h"
#include "Timer0.c"

extern BOOL newValue; 
char textbuf1[17];  	 		//declaration of array of 17 characters 
char textbuf2[17];  	 		//declaration of array of 17 characters 

int waarde = 0;  	 		//arbitrary value of integer x 
BOOL count = FALSE;
int delay=0;
int y = 0;
int main(void) { 
struct Time {
int hours;
int minutes;
int seconds;
int onehundreds;	
};

struct Time xTime;  // xDate is a variable of the structure Date. 
xTime.hours = 0; 
xTime.minutes = 0; 
xTime.seconds = 0; 
xTime.onehundreds = 0;



initEvaluationBoard();  
initEINT0(); 
lcd_init();
//init_T0();	


while (1)  {

if (INT0) {

sprintf(textbuf1,"  %d :  %d :  %d ", 0,0,0);set_cursor(0, 1);  	 		//cursor position is moved to the lower line
set_cursor(0, 0);  	 		//cursor position is moved to the lower line

lcd_print(textbuf1);	 		//the text is written to the Lcd-module 
	
}
else  {
while (1)  {
	for (delay =0;delay < 10000; delay++)
{
//do nothing
}  
				xTime.onehundreds ++;
				if(xTime.onehundreds  == 100)
				{
						xTime.onehundreds  = 0;
						xTime.seconds++;
						if(xTime.seconds == 60)
						{
								xTime.seconds = 0;
								xTime.minutes++;
						}
				}
				sprintf(textbuf1,"  %d :  %d :  %d ", xTime.minutes, xTime.seconds,  xTime.onehundreds);
	
	
		
	
set_cursor(0, 0);  	 		//cursor position is moved to the lower line
lcd_print(textbuf1);	 		//the text is written to the Lcd-module 

			
				
}
for (delay =0;delay < 10000; delay++)
{
//do nothing
}  

}
}
}
/************* Interrupt service routine for EINT0 ****************************/ 
__irq void EINT0_ISR(void) {          // interrupt service routine 
/************************************************/ 
// Place here your own code 
//count=TRUE;
/************************************************/ 
EXTINT |= 0x01;                     // clears EINT0 interrupt flag 
VICVectAddr = 0;                    // Update interrupt priority hardware 




}; 

/************* Initializing code for EINT0 ****************************/
void initEINT0(void) { 
PINSEL4 |= (1<<20); // select EINT0 pin.function
EXTMODE |= 1; // select level-sensitive EINT0. 
EXTINT |= 0x01;   // clears EINT0 interrupt flag
VICVectPriority14=15; // lowest priority. 
VICIntEnable = (1<<14); // enable interrupt source 14 (EINT0). 
VICVectAddr14 = (unsigned long) EINT0_ISR; // Address of Interrupt Service Routine 
}

Ik heb de 2e While(1) loop toegevoegd zodat ik niet steeds de INT0 button ingedrukt hoef te houden. Hoe kan ik dit anders doen? Nu werkt de reset namelijk niet meer omdat het programma niet uit de while loop komt.

Hoe kan ik nu het beste verder met mijn code? Alvast bedankt voor jullie tips.
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan