Modifying the hello program

Started by Caleno, May 30, 2003, 08:57:44 AM

Previous topic - Next topic

Caleno

I need to modify the hello program like this. Instead of displaying "hello world" the whole time. I need to display a number contained in a variable. This number will be deducted by one every 5 seconds. The resulting number will be the new value on the variable and will be displayed on the screen.
I have made some changes on the hello program because it has the idea I want to convey, but I am not that skillful yet.
Can you help me?
thanks in advance

Here is the midification I have done...but it does not work.


***********************************************************
/*------------------------------------------------------------------------------
HELLO.C - adapted for the P89LPC932 and the Keil MCB900 Microcontroller Board

Copyright 1995-2002 Keil Software, Inc.
------------------------------------------------------------------------------*/

#include               /* special function register declarations   */
                                       /* for the Philips P89C932 device           */

#include                /* prototype declarations for I/O functions */

/* The delay C function is a for loop that
needs about 6 seconds execution time */
static void delay (void)  {
unsigned long i;

  for (i = 0; i < 444444; i++)  {     /* waste timea and */
    ;                                             /* do notthing */
  }                           }                           
/*------------------------------------------------
The main C function.  Program execution starts
here after stack initialization.
------------------------------------------------*/

void main() {
unsigned int W;                  /* variable

//  P2M1 = 0;
//  P1M1 = 0;

//  SCON   = 0x52;                    /* initialize UART */
//  BRGR0  = 0xF0;                    /* 9600 baud, 8 bit, no parity, 1 stop bit */
//  BRGR1  = 0x02;
//  BRGCON = 0x03;
 

//  P2 = 0x55;
/*------------------------------------------------
Note that an embedded program never exits (because
there is no operating system to return to).  It
must loop and execute forever.
------------------------------------------------*/
      while (1)
//    P2 ^= 0xFF;               /* Toggle port 2 pins each time we print */
 W = 120;         /* value to be deducted and displayed
         W = W-1;          
printf ("\n This is the present amount: %d, *W");  /*is this right?
    delay ();                    /* Delay about 6 seconds               */
***********************************************************


Andy Ayre

Try:

printf("\n This is the present amount: %u", W);

This is really standard C. There are a couple of deviations that Keil makes from the standard, but the syntax for printf is basically the same.

You also need braces for your infinate loop:

while(1)
{
  // do stuff here
}

A good book to read (along with the Keil manuals) is:

"The C Programming Language" by Kernighan and Richie.

Note that although I have helped you this time, this is a discussion forum for Flash Magic and WinISP only. Your programming and microcontroller questions would be better posted in one of the following locations:

www. 8052.com
www.philipsmcu.com in the discussion forum

Embedded Systems Academy, Inc.
support at esacademy dot com