This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

having problem with debugging a code (digital timer)

hi everyone
i'm using uvision4 and stm32f103ve
i have written and successfully compiled this code (0 errors)
but it does't work at simulation
it suppose when you press D4 (the key that increases the second)two times (it means that you intered 2 sec)after 2 sec it has to turn the led(which is connected to the C5)
i guess it has problem with delay function and its declaration.
Any help on this problem would be greatly appreciated!

#include "stm32f10x.h"
#include "system_stm32f10x.h"
#include "stm32f10x_conf.h"
#include "Delay.h"
#include "LED.h"
#include "Keys.h"
#include "lcd4bit.h"
#include <stdio.h>
#include <string.h>
                                                          //**************//
static __IO uint32_t TimingDelay;
uint8_t LCDBuff[50];
/* Private function prototypes -----------------------------------------------*/
void _delay_ms(__IO uint32_t nTime);
void _delay_us(__IO uint32_t nTime);
void TimingDelay_Decrement(void);
                              //**************//
int main(void){
         //****************************//
    SystemInit();       //72MHz
        //****************************//
        while(1){
        char A[16];
        int counter = 0;
        int i = 0;
        int m = 0 , h = 0;
        int flag = 1;
        void delay_init(u8 SYSCLK);
    lcd_init();         // vase lcd
        IOInit();      //baraye faal krdan clk va shenasandane pc5 , led.
        //delay_init(72000000);
        lcd_clear();
        KeysInit();   //faal krdane clk klid ha
        while(flag)     {
                 sprintf(A,"Time: %02u:%02u:%02u ",h,m,counter);
             lcd_clear();
             lcd_putsf(A);
                     if(PinA5 == 1){               //klide ejra
                                 flag = 0;
                                 break;
                                 }
                 if(PinA3 == 1) {                                 //entekhabe sanye daghighe va saat be
                                         delay_ms(500);
                                         i++;
                                         if(i == 3){i = 0;}                     //       charkhesh

                                 }
                  if(PinA4 == 1 )       {                                 //entekhabe sanye daghighe va saat be
                                                delay_ms(500);
                                            i--;
                                            if(i == -1){i = 2;}                                         //       charkhesh

                                 }
          if(PinA1 == 1 && i == 0)      {                               // pinA.1 afzayesh midahad   i=0 counter ast
                                                        delay_ms(500);
                                                counter++;
                                                    if(counter == 60){                                                   // bazgasht
                                                              counter = 0;

                                                }

                                 }
                  if(PinA2 == 1 && i == 0){                       //pinA.2 kahesh midahad
                                           delay_ms(500);
                                           counter--;
                                                 if(counter == -1){
                                                         counter = 59;


                                                }

                                 }
          if(PinA1 == 1 && i == 1)      {                                       //daghighe
                                            delay_ms(500);
                                                m++;
                                                 if(m == 60){                                                   //charkhesh
                                                 m = 0;
                                                 }
                                 }
                   if(PinA2 == 1 && i == 1){
                                           delay_ms(500);
                                           m--;
                                                if(m == -1){
                                                   m =59;

                                                }

                                 }
                    if(PinA1 == 1 && i == 2)    {                                                //saat
                                        delay_ms(500);
                                                h++;
                                 }
                        if(PinA2 == 1 && i == 2){
                                        delay_ms(500);
                                                h--;
                                                if(h == -1){
                                                h = 0;
                                                }

                                 }
                                 }

while(!flag) {
            sprintf(A,"Time: %02u:%02u:%02u ",h,m,counter);
        lcd_clear();
        lcd_putsf(A);
                      if(PinA3 == 1 && PinA4 == 1){                               //3,4 ba hm ghat mikonnand
                             break;
                                         }
                delay_ms(1000);
                counter--;                                                      //sanie km she
                  if(counter == -1 && (h!=0 || m!=0))
                                {
                                        counter = 59;
                                        m--;
                                }
                  if(m == -1 && h != 0){
                                        m = 59;
                                        h--;
                                }


                        if(counter == -1 && h == 0 && m ==0 ){
                                counter = 0;
                                sprintf(A,"Time: %02u:%02u:%02u ",h,m,counter);
                lcd_clear();
                lcd_putsf(A);
                    LED1_1;                //led 1 k b porte B.0 vasle roshan she
                delay_ms(2000);
                LED1_0;            //led 1 k b porte B.0 vasle khamoosh she
                    flag = 1;
                break;

                                }



                                        }
     }


           }


0