Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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 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.Multi tasking??
https://www.mikroe.com/news/view/676/rtos-in-pic-microcontrollers-a-tutorial-for-mikroc/Or do you just need to monitor external events...
You need to familiarize yourself with RTOS... Threre are many free RTOS versions out there..
Basically you need to split processor time between tasks..
Let both external sources fire an interruptThese two definitions are a mile apart! Which processor are you going to use??
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.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
How can i do that using mikroc if that"s a better option for u. Thanks.I think a microcontroller is great at multitasking it can do this task then that task.. 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.
Nope thats not wat m saying. Ive done that already.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.
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 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.
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()
}
}
for(;;)
{
Multiplexing();
MatrixCalender()
}
}
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!!