Home - Search - Members
Full Version: IO PORT PROGRAMING CHALANGE
caze
Jun 28 2008, 12:32 PM
suppose in an industrial application we have to controll some events ,which are time dependent, using microcontroller.

the problem is like : there are 10 deveces . and these devices runs for 10 second (say) if it gets an input
signal.(note : all these 10 devices gets input signals randomly i.e. some times 2 devices may get input signal
,sometimes 4 or 5 or 8 or all 10 etc.)
now suppose if in first time slot (i.e. 10 second) 5 devices are running and before the end of first time slot
another 2 devices gets input signal .... and so on ...

how would u controll it using single microcontroller .
Arun Kumar V
Jun 28 2008, 7:02 PM

hi caze,

i don't see where you are having problem, can you be more clear


Arun
sashijoseph
Jun 28 2008, 8:27 PM
Would the devices go off after 10s by themselves or does the micro have to switch them off after the time slot elapses?
shyam
Jun 28 2008, 10:57 PM
hi Caze

here comes the fundamental RTOS functionalities Semaphores mutex and mutual exclusion.
by using one or more than one or all of the above techniques we can
1. set priorities to the Tasks
2. make other tasks wait for the previous o complete, without missing input signals.
3. store the sequence of inputs in page tables (as in your computer) and then proccess accordingly may be by
a. FIFO or Priority basis or both.


that is the reason most of the industrial automation tenders nowadays necessarily mention RTOS as the main part of the product.

i believe using RTOS will solve the problem, still if ur uController doesnt support it.. u can make the necessary routines yourselves.
caze
Jun 29 2008, 5:28 AM
hi @ sashijoseph,

devices has to be stoped by microcontroller itself.




caze
Jun 29 2008, 5:32 AM
hi shyam,
great idea. but i guess writing routine for 8051 will be too lengthy and tedious work .

is it possible to
shyam
Jun 29 2008, 8:37 AM
yes it can be written

u will find some keil examples with RTX51.
a little effort and u can get the source of the kernel too

ammend it according to ur need and u'll get the solution..
here take a look this is a 51 code!

CODE:

/******************************************************************************/
/*                                                                            */
/*   TRAFFIC.C:  Traffic Light Controller using the C-51 COMPILER             */
/*                                                                            */
/******************************************************************************/

char code menu[] =
   "\n"
   "+***** TRAFFIC LIGHT CONTROLLER using C51 and RTX-51 tiny *****+\n"
   "| This program is a simple Traffic Light Controller.  Between  |\n"
   "| start time and end time the system controls a traffic light  |\n"
   "| with pedestrian self-service.  Outside of this time range    |\n"
   "| the yellow caution lamp is blinking.                         |\n"
   "+ command -+ syntax -----+ function ---------------------------+\n"
   "| Display  | D           | display times                       |\n"
   "| Time     | T hh:mm:ss  | set clock time                      |\n"
   "| Start    | S hh:mm:ss  | set start time                      |\n"
   "| End      | E hh:mm:ss  | set end time                        |\n"
   "+----------+-------------+-------------------------------------+\n";


#include <reg52.h>                    /* special function registers 8052      */
#include <rtx51tny.h>                 /* RTX-51 tiny functions & defines      */
#include <stdio.h>                    /* standard I/O .h-file                 */
#include <ctype.h>                    /* character functions                  */
#include <string.h>                   /* string and memory functions          */


extern getline (char idata *, char);  /* external function:  input line       */
extern serial_init ();                /* external function:  init serial UART */

#define INIT      0                   /* task number of task:  init           */
#define COMMAND   1                   /* task number of task:  command        */
#define CLOCK     2                   /* task number of task:  clock          */
#define BLINKING  3                   /* task number of task:  blinking       */
#define LIGHTS    4                   /* task number of task:  signal         */
#define KEYREAD   5                   /* task number of task:  keyread        */
#define GET_ESC   6                   /* task number of task:  get_escape     */

struct time  {                        /* structure of the time record         */
  unsigned char hour;                 /* hour                                 */
  unsigned char min;                  /* minute                               */
  unsigned char sec;                  /* second                               */
};

struct time ctime = { 12,  0,  0 };   /* storage for clock time values        */
struct time start = {  7, 30,  0 };   /* storage for start time values        */
struct time end   = { 18, 30,  0 };   /* storage for end   time values        */

sbit  red    = P1^2;                  /* I/O Pin:  red    lamp output         */
sbit  yellow = P1^1;                  /* I/O Pin:  yellow lamp output         */
sbit  green  = P1^0;                  /* I/O Pin:  green  lamp output         */
sbit  stop   = P1^3;                  /* I/O Pin:  stop   lamp output         */
sbit  walk   = P1^4;                  /* I/O Pin:  walk   lamp output         */
sbit  key    = P1^5;                  /* I/O Pin:  self-service key input     */

char idata inline[16];                /* storage for command input line       */


/******************************************************************************/
/*        Task 0 'init': Initialize                                           */
/******************************************************************************/
void init (void) _task_ INIT  {       /* program execution starts here        */
  serial_init ();                     /* initialize the serial interface      */
  os_create_task (CLOCK);             /* start clock task                     */
  os_create_task (COMMAND);           /* start command task                   */
  os_create_task (LIGHTS);            /* start lights task                    */
  os_create_task (KEYREAD);           /* start keyread task                   */
  os_delete_task (INIT);              /* stop init task (no longer needed)    */
}


bit display_time = 0;                 /* flag:  signal cmd state display_time */

/******************************************************************************/
/*        Task 2 'clock'                                                      */
/******************************************************************************/
void clock (void)  _task_ CLOCK  {
  while (1)  {                        /* clock is an endless loop             */
    if (++ctime.sec == 60)  {         /* calculate the second                 */
      ctime.sec = 0;
      if (++ctime.min == 60)  {       /* calculate the minute                 */
        ctime.min = 0;
        if (++ctime.hour == 24)  {    /* calculate the hour                   */
          ctime.hour = 0;
        }
      }
    }
    if (display_time)  {              /* if command_status == display_time    */
      os_send_signal (COMMAND);       /* signal to task command: time changed */
    }
    os_wait (K_IVL, 100, 0);          /* wait interval:  1 second             */
  }
}


struct time rtime;                    /* temporary storage for entry time     */

/******************************************************************************/
/*        readtime: convert line input to time values & store in rtime        */
/******************************************************************************/
bit readtime (char idata *buffer)  {
  unsigned char args;                          /* number of arguments         */

  rtime.sec = 0;                               /* preset second               */
  args = sscanf (buffer, "%bd:%bd:%bd",        /* scan input line for         */
                 &rtime.hour,                  /* hour, minute and second     */
                 &rtime.min,
                 &rtime.sec);
 
  if (rtime.hour > 23  ||  rtime.min > 59  ||  /* check for valid inputs      */
      rtime.sec > 59   ||  args < 2        ||  args == EOF)  {
    printf ("\n*** ERROR: INVALID TIME FORMAT\n");
    return (0);
  }
  return (1);
}



#define ESC  0x1B                     /* ESCAPE character code                */

bit   escape;                         /* flag: mark ESCAPE character entered  */

/******************************************************************************/
/*        Task 6 'get_escape': check if ESC (escape character) was entered    */
/******************************************************************************/
void get_escape (void) _task_ GET_ESC  {
  while (1)  {                                 /* endless loop                */
    if (_getkey () == ESC)  escape = 1;        /* set flag if ESC entered     */
    if (escape)  {                             /* if escape flag send signal  */
      os_send_signal (COMMAND);                /* to task 'command'           */
    }
  }
}


/******************************************************************************/
/*        Task 1 'command': command processor */
/******************************************************************************/
void command (void) _task_ COMMAND  {
  unsigned char i;

  printf (menu);                               /* display command menu        */
  while (1)  {                                 /* endless loop                */
    printf ("\nCommand: ");                    /* display prompt              */
    getline (&inline, sizeof (inline));        /* get command line input      */

    for (i = 0; inline[i] != 0; i++)  {        /* convert to uppercase        */
      inline[i] = toupper(inline[i]);
    }

    for (i = 0; inline[i] == ' '; i++);        /* skip blanks                 */

    switch (inline[i])  {                      /* proceed to command function */
      case 'D':                                /* Display Time Command        */
        printf ("Start Time: %02bd:%02bd:%02bd    "
                "End Time: %02bd:%02bd:%02bd\n",
                 start.hour, start.min, start.sec,
                 end.hour,   end.min,   end.sec);
        printf ("                        type ESC to abort\r");

        os_create_task (GET_ESC);              /* ESC check in display loop   */
        escape = 0;                            /* clear escape flag           */
        display_time = 1;                      /* set display time flag       */
        os_clear_signal (COMMAND);             /* clear pending signals       */

        while (!escape)  {                     /* while no ESC entered        */
          printf ("Clock Time: %02bd:%02bd:%02bd\r",      /* display time     */
                   ctime.hour, ctime.min, ctime.sec);
          os_wait (K_SIG, 0, 0);               /* wait for time change or ESC */
        }

        os_delete_task (GET_ESC);              /* ESC check not longer needed */
        display_time = 0;                      /* clear display time flag     */
        printf ("\n\n");
        break;

      case 'T':                                /* Set Time Command            */
        if (readtime (&inline[i+1]))  {        /* read time input and         */
          ctime.hour = rtime.hour;             /* store in 'ctime'            */
          ctime.min  = rtime.min;
          ctime.sec  = rtime.sec;
        }
        break;

      case 'E':                                /* Set End Time Command        */
        if (readtime (&inline[i+1]))  {        /* read time input and         */
          end.hour = rtime.hour;               /* store in 'end'              */
          end.min  = rtime.min;
          end.sec  = rtime.sec;
        }
        break;

      case 'S':                                /* Set Start Time Command */
        if (readtime (&inline[i+1]))  {        /* read time input and         */
          start.hour = rtime.hour;             /* store in 'start'            */
          start.min  = rtime.min;
          start.sec  = rtime.sec;
        }
        break;

      default:                                 /* Error Handling              */
        printf (menu);                         /* display command menu        */
        break;
    }  
  }
}


/******************************************************************************/
/*        signalon: check if clock time is between start and end              */
/******************************************************************************/
bit signalon (void)   {
  if (memcmp (&start, &end, sizeof (struct time)) < 0)  {
    if (memcmp (&start, &ctime, sizeof (struct time)) < 0  &&
        memcmp (&ctime, &end,   sizeof (struct time)) < 0)  return (1);
  }
                                               
  else  {
    if (memcmp (&end,   &ctime, sizeof (start)) > 0  &&
        memcmp (&ctime, &start, sizeof (start)) > 0)  return (1);
  }
  return (0);                                  /* signal off, blinking on     */
}


/******************************************************************************/
/*        Task 3 'blinking': runs if current time is outside start & end time */
/******************************************************************************/
void blinking (void) _task_ BLINKING  {        /* blink yellow light          */
  red    = 0;                                  /* all lights off              */
  yellow = 0;
  green  = 0;
  stop   = 0;
  walk   = 0;

  while (1)  {                                 /* endless loop                */
    yellow = 1;                                /* yellow light on             */
    os_wait (K_TMO, 150, 0);                   /* wait for timeout: 150 ticks  */
    yellow = 0;                                /* yellow light off            */
    os_wait (K_TMO, 150, 0);                   /* wait for timeout: 150 ticks  */
    if (signalon ())  {                        /* if blinking time over       */
      os_create_task (LIGHTS);                 /* start lights                */
      os_delete_task (BLINKING);               /* and stop blinking           */
    }
  }
}


/******************************************************************************/
/*      Task 4 'lights': executes if current time is between start & end time */
/******************************************************************************/
void lights (void) _task_ LIGHTS  {            /* traffic light operation     */
  red    = 1;                                  /* red & stop lights on        */
  yellow = 0;
  green  = 0;
  stop   = 1;
  walk   = 0;
  while (1)  {                                 /* endless loop                */
    os_wait (K_TMO, 150, 0);                   /* wait for timeout: 150 ticks */
    if (!signalon ())  {                       /* if traffic signal time over */
      os_create_task (BLINKING);               /* start blinking              */
      os_delete_task (LIGHTS);                 /* stop lights                 */
    }
    yellow = 1;
    os_wait (K_TMO, 150, 0);                   /* wait for timeout: 150 ticks */
    red    = 0;                                /* green light for cars        */
    yellow = 0;
    green  = 1;
    os_clear_signal (LIGHTS);
    os_wait (K_TMO, 200, 0);                   /* wait for timeout: 200 ticks */
    os_wait (K_TMO + K_SIG, 250, 0);           /* wait for timeout & signal   */
    yellow = 1;
    green  = 0;
    os_wait (K_TMO, 150, 0);                   /* wait for timeout: 150 ticks */
    red    = 1;                                /* red light for cars          */
    yellow = 0;
    os_wait (K_TMO, 150, 0);                   /* wait for timeout: 150 ticks */
    stop   = 0;                                /* green light for walkers     */    
    walk   = 1;
    os_wait (K_TMO, 250, 0);                   /* wait for timeout: 250 ticks */
    os_wait (K_TMO, 250, 0);                   /* wait for timeout: 250 ticks */
    stop   = 1;                                /* red light for walkers       */        
    walk   = 0;
  }
}


/******************************************************************************/
/*        Task 5 'keyread': process key stroke from pedestrian push button    */
/******************************************************************************/
void keyread (void) _task_ KEYREAD  {
  while (1)  {                                 /* endless loop                */
    if (key)  {                                /* if key pressed              */
      os_send_signal (LIGHTS);                 /* send signal to task lights  */
    }
    os_wait (K_TMO, 2, 0);                     /* wait for timeout: 2 ticks   */
  }
}
 
sashijoseph
Jun 29 2008, 11:09 PM
@Caze
Shyam's method is elegant and the correct way to go.

But you could also use the 8051's 2 timers and 8 external timers(2xLM558) to control all 10 devices.The micro would poll 10 input pins continuously and trigger the timers whenever it detects an input.
Would,by any chance, a device already triggered and yet to complete it's 10s,get another input signal?
Arun Kumar V
Jul 1 2008, 8:48 AM
i feel its no more a challenge if we used external analog timers, in such case we don't need the micro at all because the input signals can trigger the timers which are hard wired (RC network) for 10 sec delay.

the Job can be done without using external timers and using only one internal timer of 8051. after a lot of thought process i have come up with the following approach:


1) wire 10 pins on micro as inputs

2) load timer0 with 50 milliSec values and start timer0

3) wire External interrupt(EX0) pin to all the 10 inputs with help of diodes in such a way that when any of the 10 inputs are received the EX0 pin along with the input pin/s is brought low( logic 0).

4) in the External Int. ISR check which pin/s are grounded and set a flag/s for that particular input pin/s and give output/s (start the device/s)

5) in the timer0 ISR declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/s

6) even when some devices are running and some other new device/s is triggered the counter for that particular new device is also incremented along with the old running ones

7) all the checking and control is done in ISRs of External int.0 and timer int.0

8) time required for overhead instructions may cause slight delay and therefore normal 12 cycle 8051 clocked @ 12Mhz or 24 Mhz should be avoided for tasks like theses one should use the world's fastest 8051 " DS89C450" clocked at 24Mhz which is 10 times faster than normal 8051 and each instruction takes 40-45 nanosecs and task can be completed with near accuracy.

9) if both the Ex0 interrupt and 50mSec timer int. occur at the same time,by default first the EX0 is serviced followed by timer int.

10) the tick time of 50 msec can be reduced to say 20msec but to get 10 sec delay we would require to count 500 interrupts but the 8 bit counter can count max upto 255D

if interested i can write the code in asm and post it here.


Arun




Ajay
Jul 1 2008, 11:16 PM
Arun Kumar V wrote ...
3) wire External interrupt(EX0) pin to all the 10 inputs with help of diodes in such a way that when any of the 10 inputs are received the EX0 pin along with the input pin/s is brought low( logic 0).

ORing the inputs will be better
sashijoseph
Jul 2 2008, 8:15 PM
^^but then which of the 10 inputs caused the interrupt wouldn't be traceable.I think that's why Arun has ORed the inputs to the INT pin(with diodes) and simultaneously used parallel IO for tracing the source of the interrupt.

Very thoughtful Arun.
pdi33
Jul 2 2008, 8:32 PM
I think that is a near perfect solution for the problem i woud say by arun.

caze
Jul 4 2008, 11:15 AM
hi @ arun ,

thanks a lot .......

and ill be so thankful to u if u can post asm program here .
Arun Kumar V
Jul 6 2008, 7:14 PM


Sorry for late reply, was on a short trip.

Thank you SJ and Pdi33 !

caze - i'll post the asm code and schematic today


Arun
Arun Kumar V
Jul 7 2008, 6:46 PM
hello caze,

as promised here's my code and schematic, i have written for 8 I/Os your task is to further increase it to 10 I/Os (its easy after you go thru the code) - Enjoy !








: code deleted by Arun




i have simulated and tested the code using Ds89C430 and it works well !


Arun
Ajay
Jul 8 2008, 8:15 AM
wow!

how bout starting programming competetions?

I am not sure how good it will be.. but its gonna be fun..
Arun Kumar V
Jul 8 2008, 9:16 AM


Sure, Why not ?...............





Arun
pdi33
Jul 9 2008, 7:39 AM
nice idea ajay,
would really tickle our old grey cells.. and help a few newcomers in many ways.
when do we start?
shyam
Jul 9 2008, 8:26 AM

every competition needs a judge...
i believe we can help each other out.. for sure...
but to judge who is better wud not be that easy
pdi33
Jul 9 2008, 8:05 PM
wisely said shyam.

hmmm, too many offtopic posts here i think.
Ajay
Jul 10 2008, 6:57 AM
Well..
I have answer to that too

Competitions will go like this..

1. Problem will be post on forum and entries will be accepted till a fixed date
2. After entries are received, A new thread will be created
3. all entries will be displayed and we will have voting on the basis of logic/code efficiency
4. After voting date is over. We will have our winner

>> We have to promise ourself to vote for the best
pdi33
Jul 10 2008, 7:49 AM
that would be nice. but will it cover all possible forum topics ? AVR/8051/PIC/VB.
i.e. will there be individual probems posted for each forum heading?.
anyways, looks very promising and attractive.
ijatorzaty
Aug 30 2008, 5:23 PM
Arun Kumar V wrote ...

hello caze,

as promised here's my code and schematic, i have written for 8 I/Os your task is to further increase it to 10 I/Os (its easy after you go thru the code) - Enjoy !








: code deleted by Arun




i have simulated and tested the code using Ds89C430 and it works well !


Arun


stated at the above of the diagram, u've posted code, but where is it? could u repost it, once again...so, it could be my reference for my assignment, i hope u'll consider my request...
pdi33
Aug 31 2008, 12:49 AM
@izator..,
as u can see, arun has posted the most important part of ur assignment which is the principle of operation and hardware which is more than half of ur assignment done. i would assume that writing the code for the above hardware should be quite simple for u if u have really understood the principle explained in the previous posts of this thread.
I am in perfect acceptance of aruns decision to delete the code as the same assignment seems to have been given to most of the members of this forum from ur place and it would be unfair (especially to ur faculty who gave u people this assignment) if most of ur collegues just download the code and complete the assignment without really understanding the concept( which is why u were given the assignemnt in the first place, right?).

So i would advice u on starting on something and then we can always suggest/comment on it.

good luck
Mr
Sep 4 2008, 3:35 PM
10) the tick time of 50 msec can be reduced to say 20msec but to get 10 sec delay we would require to count 500 interrupts but the 8 bit counter can count max upto 255D

i need 30 seconds delay which is 600D but the max is 255D
so how do i get 30 secs? by setting tick time higher than 50msec? Biggest is 60+msec?
but still cannot get a total of 30seconds.
pls teach me how to get 30 secs...

Edit: Just think of an idea of making 2 loops, but the exact coding still not sure about it...
pdi33
Sep 4 2008, 9:24 PM
well u thought of it right. but to generate a 30seconds tick (that is a very long time ), u may have to change the timer mode to 16 bits ( two bytes) and further add a two byte counter in the overflow interrupt. 30 seconds = 30,000,000 uS. == total 4 byte counter.
Mr
Sep 5 2008, 1:40 AM
Arun Kumar V wrote ...

hello caze,

as promised here's my code and schematic, i have written for 8 I/Os your task is to further increase it to 10 I/Os (its easy after you go thru the code) - Enjoy !








: code deleted by Arun




i have simulated and tested the code using Ds89C430 and it works well !


Arun


another noob question here, hope u all dun mind...
by comparing Arun's schematic n Junied's schematic (http://rapidshare.de/files/40330614/imp_scheme.pdf.html)
Arun's connect those buttons to P3.2(INT0) which Junied did not.
I know it is for interrupt purpose, but i not really clear about tis part.
Is it we must use interrupts to implemented tis functions? Is there any others way?
For example, below is a sample code i search thru the internet, it can poll between 2 inputs and countdown 10 secs but it does not uses interrupts. Is tis code correct?

(If you pressed switch A, and your program goes into a delay loop to give you the 10 sec delay, then switch B will not be polled, and therefore has no effect while the system is waiting for this 10 sec delay to complete.

The program below should give you some idea. It is not debugged, but the idea is there.

The two switches have to be polled regularly. Let the timer runs freely and overflow every 50 ms. If switch A is pressed, initialise the value of R1 to 200. Decrement R1 everytime the timer overflow. After 200 overflow (200 x 50ms = 10 s), R1 becomes zero, and the program turn off LED A. LED B is separately controlled by the value in R2.


MOV TMOD,#10H ; CONFIGURE TIMER 1
MOV TH1,#3CH ; ASSUME 12 MHZ CRYSTAL
MOV TL1,#B0H ; TIMER TAKES 50MS TO OVERFLOW
SETB TR1 ; START TIMER 1

POLL: ; POLL FOR THE SWITCHES
JNB P1.0,AA1 ; JUMP IF SWITCH A IS PRESSED
JNB P1.1,BB1 ; JUMP IF SWITCH B IS PRESSED

POLL2:
JNB TF1,POLL ; TIMER NOT OVERFLOW YET, CONTINUE TO POLL
CLR TF1
MOV TH1,#3CH
MOV TL1,#B0H
CJNE R1,#0,CNTDOWN_A
SETB P3.0 ; OFF LED A
CJNE R2,#0,CNTDOWN_B
SETB P3.1 ; OFF LED B
SJMP POLL

AA1:
MOV R1,#200D ; START TIMING
CLR P3.0 ; ON LED A
SJMP POLL2

BB1:
MOV R2,#200D
CLR P3.1 ; ON LED B
SJMP POLL2

CNTDOWN_A:
DEC R1
SJMP POLL

CNTDOWN_B:
DEC R2
SJMP POLL
)
Mr
Sep 5 2008, 2:13 AM
pdi33 wrote ...

well u thought of it right. but to generate a 30seconds tick (that is a very long time ), u may have to change the timer mode to 16 bits ( two bytes) and further add a two byte counter in the overflow interrupt. 30 seconds = 30,000,000 uS. == total 4 byte counter.


I do not understand "and further add a two byte counter in the overflow interrupt. 30 seconds = 30,000,000 uS. == total 4 byte counter."
Wat u mean by overflow interrupt? add 2 byte counter?
By setting timer mode to 16bits(TMOD,#10H) blah blah blah i get 50mS each cycle.
den i MOV R1,#200 to get 10secs. I cant MOV R1,#600 to get 30secs becoz the max is 255 only.
Can i do like tis? Like creating delay for multiplexing?
LOOP1: MOV R1,#200
LOOP2: MOV R2,#3 ;200*3=600 =)
LOOP3: DJNZ R1,$
DJNZ R2,LOOP2

p/s: becoz on the other thread Arun said tis "3) once Key is detected, particular LED is Lit and timer1 is loaded for 30sec delay
( 50mS X 20d = 1000mS or 1 Sec, for 30 sec increment a Register 30 times) after the delay the led is switched off."
Mr
Sep 5 2008, 5:50 AM
5) in the timer0 ISR declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/s

how to do tis part?
already confuse between timer n counter, somore declare counters in timer0 ISR.
totally blur...
Arun Kumar V
Sep 5 2008, 11:55 AM
Hello Mr.shabiul,

i feel you are trying to do too many things at the same time, pl. follow a step by step approach.


the solution i offered here is for this particular Challenge, so the connecting of Int0 pin with other input port pins works in this context and you don't have to connect it this way always in your other circuits.

now about the timer delay.

You have to use timer ISR ( interrupt Service Rotuine). in Data seg ( i,e RAM) define variables by some name like count_1......count_10 and also 10 flags by name like Flag_1.....Flag_10 and now read the algorithm carefully (point no.5):

5) in the timer0 ISR declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/s



and now for 30 sec delay question.

first make a delay for 1 Sec and then use this 1 sec delay as basic tick to get multiple seconds/mins/hrs/days delay, here's a code snippet :

CODE:
MAIN:
MOV TMOD,#01H  ; TIMER 0 MODE 1
MOV  TL0,#0B0H   ;Lower Byte   ; 50 mS DELAY VALUES ( 12 Mhz XTAL)
MOV  TH0,#03CH  ;Upper Byte
MOV R1,#20D       ; COUNTER FOR 1 SEC
MOV R2,#30D       ; COUNTER FOR 30 SECS
SET   TR0               ;Run timer

CLR LED        ; LED IS ON
SJMP $


;TIMER0 ISR

CLR TR0
DJNZ R1,CONTINUE
MOV R1,#20D   ; RELOAD COUNTERS FOR NEXT CYCLE
DJNZ R2,CONTINUE
SETB  LED          ; AFTER COMPLETION OF  30 SEC DELAY OFF THE LED
MOV R2,#30D   ; RELOAD COUNTERS FOR NEXT CYCLE
 
CONTINUE:
MOV  TL0,#0B0H   ;Lower Byte   ; 50 mS DELAY VALUES ( 12 Mhz XTAL)
MOV  TH0,#03CH  ;Upper Byte
SETB TR0

RETI


Arun
Mr
Sep 5 2008, 12:23 PM
Arun Kumar V wrote ...

Hello Mr.shabiul,

i feel you are trying to do too many things at the same time, pl. follow a step by step approach.

the solution i offered here is for this particular Challenge, so the connecting of Int0 pin with other input port pins works in this context and you don't have to connect it this way always in your other circuits.

now about the timer delay.

you have to use timer ISR ( interrupt Service Rotuine). in Data seg ( i,e RAM) define variables by some name like count_1......count_10 and also 10 flags by name like Flag_1.....Flag_10 and now read the algorithm carefully (point no.5):

5) in the timer0 ISR declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/s





Arun


it is because my project also require 4 inputs which your solution offer 10 inputs, i guess it is the same thing right? So do I need to connect those 4 inputs to INT0?

by the way, i had read ur algorithm very carefully,but i m still not quite clear about it.(well, i m just a new learner to assembly coding)
5) in the timer0 ISR declare 10 counters (use registers/variables) check[/color] which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti
May you explain tis part further?
Hope to hear from u soon
Mr
Sep 6 2008, 10:35 AM
How to define others variables rather than R0-R7 in register banks 0
and without using register banks 1
becoz changing register banks looks complicated...
and my R0-R7 in register banks 0 is fully occupied...

For example
FLAG1: DS 1
den in main program
MOV FLAG1,#01H

tis giv segment type mismatch in my compliler

wat is the problem?
Arun Kumar V
Sep 6 2008, 10:43 AM

Shabiul, may be you are forgetting the 256 bytes RAM on board 8052, declare Variables in RAM and In Assembly this is how it can be done:

DSEG ORG 0020H
COUNTER_1: DS 1
COUNTER_2: DS 1

and for FLAGS

FLAG_1 BIT 1
FLAG_2 BIT 1
...................................



Arun
Mr
Sep 6 2008, 10:51 AM
why is FLAG_1 BIT 1 while COUNTER_1: DS 1?

by the way, there is alot questions in the previous posts tat you din answer me...

regarding checking the flag, THE FLAG is just normal variable or interrupt FLAG?
Arun Kumar V
Sep 6 2008, 11:20 AM
shabiul, you have edited your previous post after my reply ( see the time stamp, i replied at 11.15 pm and you modified your last reply after reading my answer at 11.21pm)

don't repeat this sought of thing.

now about your problem, bit and DS, before i clear your doubt can you tell me the difference between Port1 and Port pin 1.0


i can proceed only when you answer my above question


Arun
Mr
Sep 6 2008, 11:37 AM
i edit my post just because i got new question and i dun wan to double post.
about ur question, Port1 means the whole port1.0-1.7, port pin 1.0 means only the pin.
correct me if wrong.

by the way i mean u did not answer my previous 2-3 posts but not the last post.
Arun Kumar V
Sep 6 2008, 7:37 PM
about ur question, Port1 means the whole port1.0-1.7, port pin 1.0 means only the pin.correct me if wrong.


other way of putting it would be, port1.0 is a bit of port1 and port1 is a 8bit port.

so port1 (or any 8 bit port ) can be called as a register which is both Bit & byte addressable (i,e you can write or read a single port bit or full 8 bit register).


why is FLAG_1 BIT 1 while COUNTER_1: DS 1?


when you declare a variable in RAM area, you have to specify to compiler the size of that variable,

for eg:

COUNTER_1: DS 1 ; means the variable counter_1 is one byte wide ( like a 8 bit register)

and now declaring a flag,

FLAG_1 BIT 1 ; flag_1 is a single bit and not whole 8 bit Register.


now data moves with byte wide Variable and bit flag:

to write/read a 8 bit variable:

MOV COUNTER_1,#0FFH ; move value 255d to counter_1
MOV A,COUNTER_1 ; read value of Counter_1 to Accu

FLAG1: DS 1
den in main program
MOV FLAG1,#01H

tis giv segment type mismatch in my compliler

wat is the problem?



now with Bit :

how would you turn On or Turn Off a port bit ?

SETB P1.1
CLR P1.1

same way you can Set or clear a bit Flag:

SETB FLAG_1
CLR FLAG_1

but cannot use byte instructions with single bit variable/flag

MOV FLAG_1,#0FFH ; is wrong and gives Error

it is like writing :

MOV P1.1,#0FFH ; which is like writing 8 bit value to a single port pin (bit), this is called
" illegal syntax " by the compiler/assembler


Flag/s are used to indicate only two states i,e 1 or 0 ( a light is ON or OFF)
Variable is used to store data/value which often changes or varies ( Seconds Variable of a Clock)


Arun





nischay kumar
Sep 6 2008, 8:39 PM
@ Mr.shabiul,

I Bet even your College Professor wouldn't have explained the whole concept with such clarity as Arun did.

so the least you can do is " Thank " Arun and other moderators who are taking pain in explaining the concepts from root level.

the college professors are "paid "to solve your problems but they do not do that ( if they did, you wouldn't be asking for help in forums)

on the other hand Moderators here are doing Free social service by sharing their knowledge.

i should say you folks (your fellow country men) are Lucky to be members of this forum, because other forums Like popular 8052.com would not entertain assignments and home works ( they straight away lock/delete your posts) so thank God and thank the Mods by pressing the "Thanks button"

Mr
Sep 7 2008, 4:18 AM
Ya, i know moderators here are very nice and willing to help, tats why i stick to here.
I keep refresh the page to see if they had replied me or not, becoz i m desperate & my project is running out of time. Maybe i had ask too much question and i did not speak in proper manner, but i really appreciate their help.
the college professors are "paid "to solve your problems but they do not do that ( if they did, you wouldn't be asking for help in forums)

maybe they did,maybe they did not,its not for me to comment about it.
Well maybe the problem is with myself... i m just not good in programming.
and the text book has too little example to refer
Mr
Sep 7 2008, 4:29 AM
@Arun

thanks, u explained very well n clear. I wonder why i just dun understand such a simple thing be4....
anyway,I m still stuck in tis part 5) n 6)
5) in the timer0 ISR declare 10 counters (use registers/variables) check which flag/s is high( already set high in the Ex int.ISR), if a match is found increment that particular counter/s and reti continue till you reach 200 decimal ( 50mSec X 200 times = 10secs) once the counters reach 200 then stop the device and clear the flag/s
6) even when some devices are running and some other new device/s is triggered the counter for that particular new device is also incremented along with the old running one

How to fullfill part6 conditions? just by doing the code in part5 will do?
can i do like tis for part 5?below is sample timer ISR for 2 switches & flag1 flag2 already SETB in external INT.
T1_ISR:
PUSH ACC
PUSH PSW
MOV A,FLAG1
CJNE A,#01H,COUNTER1
CLR TR1
DJNZ R5,CONTINUE
MOV R5,#20D
DJNZ R6,CONTINUE
SETB LED1
MOV R6,#30D

CLR FLAG1 ;

COUNTER1:
MOV A,FLAG2
CJNE A,#01H,RETURN
CLR TR1
DJNZ R5,CONTINUE
MOV R5,#20D
DJNZ R6,CONTINUE
SETB LED2
MOV R6,#30D

CLR FLAG2

RETURN:
POP PSW
POP ACC

CONTINUE:
MOV TL1,#0B0H ;Lower Byte ; 50 mS DELAY VALUES ( 12 Mhz XTAL)
MOV TH1,#03CH ;Upper Byte
SETB TR1

RETI

INT0_ISR:
.
.
.
RETI


This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Rickey's World © 2003 - 2007