Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Multitasking using interrupt

Status
Not open for further replies.

Dumken

Member
Hi Goodday everyone. Pls can someone help me with a code to multitask two events with Interrupt routine on mikroc. Thank you
 
Couldn't the PWM module be considered multitasking too? Agreed, it would be a lot better if the TS simply described what s/he wanted to do.

John
 
Couldn't the PWM module be considered multitasking too? Agreed, it would be a lot better if the TS simply described what s/he wanted to do.

I would suggest he probably doesn't even know, just that he's seen the term 'multitasking' and thinks it might be a good idea (which it rarely is on microcontrollers).
 
I think a microcontroller is great at multitasking it can do this task then that task :D.. But wouldnt state machine be more in line.

Oh i forgot that's how I multitask I do this and if that's more important I do that.
 
Multi tasking??
https://www.mikroe.com/news/view/676/rtos-in-pic-microcontrollers-a-tutorial-for-mikroc/

You need to familiarize yourself with RTOS... Threre are many free RTOS versions out there..
Basically you need to split processor time between tasks..
Or do you just need to monitor external events...
Let both external sources fire an interrupt
These two definitions are a mile apart! Which processor are you going to use??
I googled out the options but it seems the ucontroller am using doesnt support such. M using pic18f45k22 and using 16mhz. All i saw online was a lib for higher models like pic24 & 32. but an alternative which was mikroc v2.15 i dont have it. I am using mikroc v4.60.
About the options of external event i didnt get u. To be frank with u. M still new to mikroc and i dont know how to go about that. What i want to do is wrt to my previous explained work on a calendar and a clock. I was able to get the two functions working but i noticed that when i call the functions(clock 7seg disp & calendar dot mat disp) in void main one function delays the other one from displaying. so i want the display to be steady. Any help on how to use interrupt or any other thing to do that. Thank u sir.
 
Last edited:
Couldn't the PWM module be considered multitasking too? Agreed, it would be a lot better if the TS simply described what s/he wanted to do.

John
john like i just explained up der. i wrote a code for a clock(using 7seg as display) and calendar(using dot mat as display) both reading its data fron ds13067. Each one is in a function of its own. When i try calling them into void main. one makes the other one not to display for a while. so i want the two events to be steady. so pls how do i do it with PWM if its a better option.
 
I think a microcontroller is great at multitasking it can do this task then that task :D.. But wouldnt state machine be more in line.

Oh i forgot that's how I multitask I do this and if that's more important I do that.
How can i do that using mikroc if that"s a better option for u. Thanks.
 
Dumken,

Do you mean: "7-segment displays multiplexing"?
That is completely different thing and possible with all MCUs.

Better sign to MikroE forum (it is free), you will get help from first hand.
Notice that they have limited free version compilers up to 2K words.
 
Dumken,

Do you mean: "7-segment displays multiplexing"?
That is completely different thing and possible with all MCUs.

Better sign to MikroE forum (it is free), you will get help from first hand.
Notice that they have limited free version compilers up to 2K words.
Nope thats not wat m saying. Ive done that already.
 
Yes, schematic and code would be nice.

However, what I understood from what you have described do not require RTOS....
With most of MCUs you can do one thing at the time - it is simple low speed hardware.
 
Last edited:
john like i just explained up der. i wrote a code for a clock(using 7seg as display) and calendar(using dot mat as display) both reading its data fron ds13067. Each one is in a function of its own. When i try calling them into void main. one makes the other one not to display for a while. so i want the two events to be steady. so pls how do i do it with PWM if its a better option.

Like suggested earlier, you don't need (or want) 'multitasking', it would be a complete and utter waste and make everything run much slower. You simply need to programme it correctly, and potentially use interrupts (although it could easily be done without interrupts if need be).

One simple method would to use a timer interrupt to drive the displays (both of them) while the main programme simply updates registers holding the values. My multiplex LED tutorials do exactly that (in assembler).

Your application, particularly when using a DS clock chip, is pretty basic and only requires a VERY low specification processor - an 18 series is pretty massive overkill (not that there's anything wrong with that).
 
I googled out the options but it seems the ucontroller am using doesnt support such. M using pic18f45k22 and using 16mhz. All i saw online was a lib for higher models like pic24 & 32. but an alternative which was mikroc v2.15 i dont have it. I am using mikroc v4.60.
About the options of external event i didnt get u. To be frank with u. M still new to mikroc and i dont know how to go about that. What i want to do is wrt to my previous explained work on a calendar and a clock. I was able to get the two functions working but i noticed that when i call the functions(clock 7seg disp & calendar dot mat disp) in void main one function delays the other one from displaying. so i want the display to be steady. Any help on how to use interrupt or any other thing to do that. Thank u sir.

The pic18 has two interrupt vectors... Low priority and high priority... When using a polled display it is far better to service the display in an interrupt.... Set up the information you want to display in RAM, then let the interrupt copy the RAM to the display.... Nigel did a tutorial with two seven segment displays using a timer and interrupts... I have transposed the ASM to C so you can use it... Are you serially loading all you data to the display, or are you using shift registers??

I don't use MikroC for the small pics but I do use it for the pic32 so I can help porting the XC8 to MikroC..

The tutorial is here click tutorial 10....
 
i still have to make some certain modifications on it thu. What i want now is just home to make it stable.
Code:
unsigned char segment[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int i,day1,daychr, dayint, hour, minute,second, secL, secH, MinL, MinH, HrL, HrH, ap, AMPM;
unsigned char day(char message[]);
void Multiplexing();
void Send_Data(unsigned short rw);
unsigned short read_ds1307(unsigned short address);
void write_ds1307(unsigned short address,unsigned short w_data);
  unsigned short Buffer[8][10] = {
                                      {0,0,0,0,0,0,0,0,0,0},
                                      {0,0,0,0,0,0,0,0,0,0},
                                      {0,0,0,0,0,0,0,0,0,0},
                                      {0,0,0,0,0,0,0,0,0,0},
                                      {0,0,0,0,0,0,0,0,0,0},
                                      {0,0,0,0,0,0,0,0,0,0},
                                      {0,0,0,0,0,0,0,0,0,0},
                                      {0,0,0,0,0,0,0,0,0,0},

                                  };
sbit Serial_Data at RC0_bit;
sbit SH_Clk at RC1_bit;
sbit ST_Clk at RC2_bit;
sbit CD4017_Clk at RC5_bit;
sbit CD4017_RST at RC6_bit;

void Send_Data(unsigned short rw){
unsigned short Mask, t, num, Flag;
for (num = 0; num<10; num++) {
  Mask = 0x01;
  for (t=0; t<8; t++){

   Flag = Buffer[rw][num] & Mask;

   if(Flag==0)
   Serial_Data = 0;

   else
   Serial_Data = 1;


   SH_Clk = 1;
   SH_Clk = 0;
   Mask = Mask << 1;
  if (Mask==256)
   Mask=0x01;
  }

}
  // Apply clock on ST_Clk
  ST_Clk = 1;
  ST_Clk = 0;
  delay_us(10);
}

unsigned short read_ds1307(unsigned short address)
{
  unsigned short r_data;
  I2C1_Start();
  I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
  I2C1_Wr(address);
  I2C1_Repeated_Start();
  I2C1_Wr(0xD1); //0x68 followed by 1 --> 0xD1
  r_data=I2C1_Rd(0);
  I2C1_Stop();
  return(r_data);
}

void write_ds1307(unsigned short address,unsigned short w_data)
{
  I2C1_Start(); // issue I2C start signal
  I2C1_Wr(0xD0); // send byte via I2C (device address + W)
  I2C1_Wr(address); // send byte (address of DS1307 location)
  I2C1_Wr(w_data); // send data (data to be written)
  I2C1_Stop(); // issue I2C stop signal
}


unsigned char BCD2UpperCh4hr(unsigned char bcd)
{
  return (((bcd & 0x1F)>> 4) + '0'); // convert upper hour to char
}

unsigned char BCD2UpperCh(unsigned char bcd)
{
  return ((bcd >> 4) + '0');
}

unsigned char BCD2LowerCh(unsigned char bcd)
{
  return ((bcd & 0x0F) + '0');
}

unsigned int chr2int(unsigned char val )
{
      return (val - '0');
}

void am2pm()
{
      hour = Bcd2Dec(hour);
      if (hour > 12)
      {
       AMPM = 0x60;
       hour = hour-12;
      }
      else
       {
       AMPM = 0x40;
       }
      hour = Dec2Bcd(hour);
}

void conv2ch(){
      second = read_ds1307(0);
      minute = read_ds1307(1);
      hour =   read_ds1307(2);
      am2pm();

     if (hour == 0x00)  // To configure midnight to show 12
         hour = 0x12;

     secL= BCD2LowerCh(second);
     secH= BCD2UpperCh(second);

     MinL= BCD2LowerCh(minute);
     MinH= BCD2UpperCh(minute);

     HrL= BCD2LowerCh(hour);
     HrH= BCD2UpperCh4hr(hour);
}
const unsigned short CharData[][8] ={
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000100},
{0b00001010, 0b00001010, 0b00001010, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010},
{0b00000111, 0b00001100, 0b00010100, 0b00001100, 0b00000110, 0b00000101, 0b00000110, 0b00011100},
{0b00011001, 0b00011010, 0b00000010, 0b00000100, 0b00000100, 0b00001000, 0b00001011, 0b00010011},
{0b00000110, 0b00001010, 0b00010010, 0b00010100, 0b00001001, 0b00010110, 0b00010110, 0b00001001},
{0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000010, 0b00000100, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00000100, 0b00000010},
{0b00001000, 0b00000100, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000100, 0b00001000},
{0b00010101, 0b00001110, 0b00011111, 0b00001110, 0b00010101, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00011111, 0b00000100, 0b00000100, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000100, 0b00001000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000100},
{0b00000001, 0b00000010, 0b00000010, 0b00000100, 0b00000100, 0b00001000, 0b00001000, 0b00010000},
{0b00001110, 0b00010001, 0b00010011, 0b00010001, 0b00010101, 0b00010001, 0b00011001, 0b00001110},
{0b00000100, 0b00001100, 0b00010100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00011111},
{0b00001110, 0b00010001, 0b00010001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00011111},
{0b00001110, 0b00010001, 0b00000001, 0b00001110, 0b00000001, 0b00000001, 0b00010001, 0b00001110},
{0b00010000, 0b00010000, 0b00010100, 0b00010100, 0b00011111, 0b00000100, 0b00000100, 0b00000100},
{0b00011111, 0b00010000, 0b00010000, 0b00011110, 0b00000001, 0b00000001, 0b00000001, 0b00011110},
{0b00000111, 0b00001000, 0b00010000, 0b00011110, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00011111, 0b00000001, 0b00000001, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000},
{0b00001110, 0b00010001, 0b00010001, 0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00001110, 0b00010001, 0b00010001, 0b00001111, 0b00000001, 0b00000001, 0b00000001, 0b00000001},
{0b00000000, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00000000},
{0b00000000, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00001000},
{0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00001000, 0b00000100, 0b00000010, 0b00000001},
{0b00000000, 0b00000000, 0b00000000, 0b00011110, 0b00000000, 0b00011110, 0b00000000, 0b00000000},
{0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00000010, 0b00000100, 0b00001000, 0b00010000},
{0b00001110, 0b00010001, 0b00010001, 0b00000010, 0b00000100, 0b00000100, 0b00000000, 0b00000100},
{0b00001110, 0b00010001, 0b00010001, 0b00010101, 0b00010101, 0b00010001, 0b00010001, 0b00011110},
{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00011111, 0b00010001, 0b00010001, 0b00010001},
{0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010001, 0b00010001, 0b00010001, 0b00011110},
{0b00000111, 0b00001000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00001000, 0b00000111},
{0b00011100, 0b00010010, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010010, 0b00011100},
{0b00011111, 0b00010000, 0b00010000, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00011111},
{0b00011111, 0b00010000, 0b00010000, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00010000},
{0b00001110, 0b00010001, 0b00010000, 0b00010000, 0b00010111, 0b00010001, 0b00010001, 0b00001110},
{0b00010001, 0b00010001, 0b00010001, 0b00011111, 0b00010001, 0b00010001, 0b00010001, 0b00010001},
{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00011111},
{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00010100, 0b00001000},
{0b00010001, 0b00010010, 0b00010100, 0b00011000, 0b00010100, 0b00010010, 0b00010001, 0b00010001},
{0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00011111},
{0b00010001, 0b00011011, 0b00011111, 0b00010101, 0b00010001, 0b00010001, 0b00010001, 0b00010001},
{0b00010001, 0b00011001, 0b00011001, 0b00010101, 0b00010101, 0b00010011, 0b00010011, 0b00010001},
{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00010000},
{0b00001110, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010101, 0b00010011, 0b00001111},
{0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010100, 0b00010010, 0b00010001, 0b00010001},
{0b00001110, 0b00010001, 0b00010000, 0b00001000, 0b00000110, 0b00000001, 0b00010001, 0b00001110},
{0b00011111, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00001110},
{0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00001010, 0b00000100},
{0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00010101, 0b00010101, 0b00001010},
{0b00010001, 0b00010001, 0b00001010, 0b00000100, 0b00000100, 0b00001010, 0b00010001, 0b00010001},
{0b00010001, 0b00010001, 0b00001010, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00011111, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00010000, 0b00011111},
{0b00001110, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001110},
{0b00010000, 0b00001000, 0b00001000, 0b00000100, 0b00000100, 0b00000010, 0b00000010, 0b00000001},
{0b00001110, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00001110},
{0b00000100, 0b00001010, 0b00010001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011111},
{0b00001000, 0b00000100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00010010, 0b00010010, 0b00010010, 0b00001111},
{0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00011100, 0b00010010, 0b00010010, 0b00011100},
{0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00010000, 0b00010000, 0b00010000, 0b00001110},
{0b00000000, 0b00000001, 0b00000001, 0b00000001, 0b00000111, 0b00001001, 0b00001001, 0b00000111},
{0b00000000, 0b00000000, 0b00000000, 0b00011100, 0b00010010, 0b00011110, 0b00010000, 0b00001110},
{0b00000000, 0b00000011, 0b00000100, 0b00000100, 0b00000110, 0b00000100, 0b00000100, 0b00000100},
{0b00000000, 0b00001110, 0b00001010, 0b00001010, 0b00001110, 0b00000010, 0b00000010, 0b00001100},
{0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00011100, 0b00010010, 0b00010010, 0b00010010},
{0b00000000, 0b00000000, 0b00000100, 0b00000000, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00000000, 0b00000010, 0b00000000, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00001100},
{0b00000000, 0b00010000, 0b00010000, 0b00010100, 0b00011000, 0b00011000, 0b00010100, 0b00010000},
{0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00001100},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00010101, 0b00010001, 0b00010001, 0b00010001},
{0b00000000, 0b00000000, 0b00000000, 0b00010100, 0b00011010, 0b00010010, 0b00010010, 0b00010010},
{0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00010010, 0b00010010, 0b00010010, 0b00001100},
{0b00000000, 0b00011100, 0b00010010, 0b00010010, 0b00011100, 0b00010000, 0b00010000, 0b00010000},
{0b00000000, 0b00001110, 0b00010010, 0b00010010, 0b00001110, 0b00000010, 0b00000010, 0b00000001},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00001100, 0b00001000, 0b00001000, 0b00001000},
{0b00000000, 0b00000000, 0b00001110, 0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00011110},
{0b00000000, 0b00010000, 0b00010000, 0b00011100, 0b00010000, 0b00010000, 0b00010000, 0b00001100},
{0b00000000, 0b00000000, 0b00000000, 0b00010010, 0b00010010, 0b00010010, 0b00010010, 0b00001100},
{0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00010001, 0b00010001, 0b00001010, 0b00000100},
{0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00010001, 0b00010001, 0b00010101, 0b00001010},
{0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00001010, 0b00000100, 0b00001010, 0b00010001},
{0b00000000, 0b00000000, 0b00010001, 0b00001010, 0b00000100, 0b00001000, 0b00001000, 0b00010000},
{0b00000000, 0b00000000, 0b00000000, 0b00011111, 0b00000010, 0b00000100, 0b00001000, 0b00011111},
{0b00000010, 0b00000100, 0b00000100, 0b00000100, 0b00001000, 0b00000100, 0b00000100, 0b00000010},
{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00001000, 0b00000100, 0b00000100, 0b00000100, 0b00000010, 0b00000100, 0b00000100, 0b00001000},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00011110, 0b00010100, 0b00000000, 0b00000000}
};

void MatrixCalender()
   {
short i, l, temp, row;
char index;

char month[3];
int monthofyear;

char weekdays[3];
int day_of_week;

        monthofyear = 2;
        switch(monthofyear){
        case  1:{
              strcpy(month, "JAN");
              break;
        }
        case  2:{
              strcpy(month, "FEB");
              break;
        }
         case  3:{
              strcpy(month, "MAR");
              break;
        }
        case  4:{
              strcpy(month, "APR");
              break;
        }
        case  5:{
              strcpy(month, "MAY");
              break;
        }
        case  6:{
              strcpy(month, "JUN");
              break;
        }
        case  7:{
              strcpy(month, "JUL");
              break;
        }
        case  8:{
              strcpy(month, "AUG");
              break;
        }
        case  9:{
              strcpy(month, "SEP");
              break;
        }
        case  10:{
              strcpy(month, "OCT");
              break;
        }
        case  11:{
              strcpy(month, "NOV");
              break;
        }
         case  12:{
              strcpy(month, "DEC");
              break;
        }
        }
day_of_week = 1;
switch(day_of_week){
        case  1:{
              strcpy(weekdays, "SUN");
              break;
        }
        case  2:{
              strcpy(weekdays, "MON");
              break;
        }
         case  3:{
              strcpy(weekdays, "TUE");
              break;
        }
        case  4:{
              strcpy(weekdays, "WED");
              break;
        }
        case  5:{
              strcpy(weekdays, "THU");
              break;
        }
        case  6:{
              strcpy(weekdays, "FRI");
              break;
        }
        case  7:{
              strcpy(weekdays, "SUN");
              break;
        }
        }

/*do
   {*/
      for (row=0; row<8; row++)
      {
      //###### WEEKDAYS #####
        index = weekdays[0];
       temp = CharData[index-32][row];
      Buffer[row][9] = (Buffer[row][9]  | temp);

       index = weekdays[1];
       temp = CharData[index-32][row];
      Buffer[row][8] = (Buffer[row][8]  | temp );

       index = weekdays[2];
       temp = CharData[index-32][row];
      Buffer[row][7] = (Buffer[row][7]  | temp );
      //##### WEEKDAYS #####

      // #### DATE ####
       index = month[0];
       temp = CharData[index-32][row];
      Buffer[row][6] = (Buffer[row][6]  | temp );

       index = month[1];
       temp = CharData[index-32][row];
      Buffer[row][5] = (Buffer[row][5]  | temp );
      // #### DATE ####

      // #### MONTHS ######
       index = month[0];
       temp = CharData[index-32][row];
      Buffer[row][4] = (Buffer[row][4]  | temp );

       index = month[1];
       temp = CharData[index-32][row];
      Buffer[row][3] = (Buffer[row][3]  | temp );

       index = month[2];
       temp = CharData[index-32][row];
      Buffer[row][2] = (Buffer[row][2]  | temp );
      // ##### MONTHS ######

      // ##### AM/PM ######
       index = month[8];
       temp = CharData[index-32][row];
      Buffer[row][1] = (Buffer[row][1]  | temp );

       index = month[9];
       temp = CharData[index-32][row];
      Buffer[row][0] = (Buffer[row][0]  | temp );
      // ##### AM/PM ######
      }

  for(l=0; l<10;l++)
    {
     for (i=0; i<9; i++) {
        send_data(i);
        CD4017_Clk = 0;
        CD4017_Clk = 1;
      //  delay_us(10);
         }  // i
      CD4017_Rst = 1;
      CD4017_Rst = 0;
    } // l
   }

void Multiplexing(){
     conv2ch();
     MatrixCalender();
    for(i=0;i<20;i++)
    {
    PORTB=segment[chr2int(secL)];
    RD5_bit=0;
    delay_ms(10);
    RD5_bit=1;

    PORTB=segment[chr2int(secH)];
    RD4_bit=0;
    delay_ms(10);
    RD4_bit=1;

    PORTB=segment[chr2int(MinL)];
    RD3_bit=0;
    delay_ms(10);
    RD3_bit=1;

    PORTB=segment[chr2int(MinH)];
    RD2_bit=0;
    delay_ms(10);
    RD2_bit=1;

    PORTB=segment[chr2int(HrL)];
    RD1_bit=0;
    delay_ms(10);
    RD1_bit=1;

    PORTB=segment[chr2int(HrH)];
    RD0_bit=0;
    delay_ms(10);
    RD0_bit=1;
   }
   }

  void main() {
  I2C1_Init(100000); //DS1307 I2C is running at 100KHz
  ADCON1 = 0x06;  // To turn off analog to digital converters
  TRISD=0;
  TRISB=0;
  ADCON0 = 0x00; // Select ADC channel AN0
  ADCON1 = 0b00001110;  // RA0 as analog input
  TRISC = 0x18;

for(;;)
{
Multiplexing();
MatrixCalender()
}
}
 

Attachments

  • Proteus design.png
    Proteus design.png
    31.3 KB · Views: 293
At first glance, this code:

Code:
for(;;)
{
  Multiplexing();
  MatrixCalender()
}
}

What you actually do is to displaying on 7 segment displays then on matrix extremely often...
That is not how multiplexing should works.

It should not to do entirely one job then other, repeating that very frequently. You should split time for each fraction of the both jobs and execute these fractions, e.g. one of 7-segment displays, then one segment for matrix, etc..

From schematic is unclear what is what and it is actually sketch. If you have many 7-segment displays and use multiplexing, you should have that much transistors, or it is ICs driven...

Look at links other members provided for similar examples.
 
Last edited:
One of the "slow down" reasons is you call "MatrixCalender();" from the main AND from "Multiplexing()" surely you only need to call it once..

If you put ALL the data through a serial stream using latching registers you will get better control!
 
Furthermore, you read from DS1307 too often, that is certainly necessary to do only once, when device is turned on. Then use MCU timer to toggle on 1s.
 
Last edited:
Furthermore, you read from DS1307 too often, that is certainly necessary to do only once, when device is turned on. Then use MCU timer to toggle on 1s.

The read isn't that bad... mS at most!! There would be more time checking "rollover" so I wouldn't bother!!

The BIG issue here is the time taken to update the LED matrices... The Matrices should be serially loaded and the 7 seg's should be latched.... Then you would have a good display!! I have shown you the way I do multiple LED matrices...

I posted some C code in another of your threads...
 
The read isn't that bad... mS at most!! There would be more time checking "rollover" so I wouldn't bother!!

Let see...

(
3 x DS1307 reading +
6 x 10ms delay for "multitasking" SSDs +
constant chr2int() conversions +
rest of the code
) x Number of main loops in 1s

=> there is simply too many things to improve and everything will work fast and smooth and low main CPU frequency.

The main issue is initial approach.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top