actor23
Member level 3
- Joined
- Dec 12, 2014
- Messages
- 56
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 8
- Activity points
- 515
When a button is pressed an interrupt is created should it be updated in the interrupt vector by writing value in an array ?
#pragma vector=VECT_MTU0_TCOV4 //overflow
_interrupt void CD4017_CLK(void) // repeat every 2 ms f.e
{
mc_delay(100); //wait 100ns for rise time of CD4017
count++; //which is 0 above the routine
if(count==1){ led_write(5); } //first digit value--- led_write(); changes the GPIO pins of TPIC6b595
if(count==2){ led_write(2); } //second digit value
-
--
----
---
--
if(count == 6){count = 0; }
etc..
char mask[10] = {0 to 9};
char select = 0;
void sendByte(unsigned char byte) {
char i = 0, mask = 0x80;
for(i = 0; i < 8; i++) {
if(byte & mask) {
DS = 1;
}
else {
DS = 0;
}
SH_CP = 1;
Delay_us(500);
SH_CP = 0;
mask >>= 1;
}
ST_CP = 1;
Delay_us(500);
ST_CP = 0;
}
void ISR() {
switch(select) {
case 0:
sendByte(mask[a]);
4017_CLK = 1;
Delay_us(200);
4017_CLK = 0;
break;
case 1:
sendByte(0xFF);
4017_CLK = 1;
Delay_us(200);
4017_CLK = 0;
break;
case 2:
sendByte(mask[b]);
case 3:
sendByte(0xFF);
4017_CLK = 1;
Delay_us(200);
4017_CLK = 0;
break;
case 4:
sendByte(mask[c]);
case 5:
sendByte(0xFF);
4017_CLK = 1;
Delay_us(200);
4017_CLK = 0;
break;
case 6:
sendByte(mask[d]);
case 7:
sendByte(0xFF);
4017_CLK = 1;
Delay_us(200);
4017_CLK = 0;
break;
case 8:
sendByte(mask[a]);
case 9:
sendByte(0xFF);
RESET 4017
}
if(++select == 10)select = 0;
}
Before answering I have to write a small piece of code and see if it works because now I have a doubt that it will not work because you cannot turn OFF output of 4017. One output pin of 4017 will be ON at a time and if you shift new data to 595 then it will be displayed in wrong digit position as you don't have option to turn OFF 4017 outputs.
if(TMR1IF_bit) {
TMR1H = 0xF8;
TMR1L = 0x30;
display[0] = mask[number / 10000];
display[1] = mask[(number / 1000) % 10];
Gorgon, your idea is smart i will try. Also, the schematic which i've drawn is not correct at all. For instance, i will put resistor on the anode of each digit. I think it blocks the unwanted current spikes also excess current. Why bjt short out i don't understand ? When Vbe reaches +0.7V switch will be on state then anode connects to +5V ?
if((select == 0) || (select == 1) || (select == 3) || (select == 5) || (select == 7) || (select == 9)) {
CD4017_CLK = 1;
Delay_us(200);
CD4017_CLK = 0;
char mask[10] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
char select = 0;
unsigned int number = 12345;
char display[5] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
char *ptr2char = 0;
sbit SH_CP at LATC0_bit;
sbit DS at LATC1_bit;
sbit ST_CP at LATC2_bit;
sbit CD4017_CLK at LATC3_bit;
sbit CD4017_RST at LATC4_bit;
//Timer1
//Prescaler 1:1; TMR1 Preload = 63536; Actual Interrupt Time : 2 ms
//Place/Copy this part in declaration section
void InitTimer1() {
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0xF8;
TMR1L = 0x30;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void sendByte(unsigned char byte) {
char i = 0, mask = 0x80;
for(i = 0; i < 8; i++) {
if(byte & mask)
DS = 1;
else
DS = 0;
SH_CP = 1;
Delay_us(50);
SH_CP = 0;
mask >>= 1;
}
ST_CP = 1;
Delay_us(50);
ST_CP = 0;
}
void Interrupt() {
if(TMR1IF_bit) {
//Enter your code here
TMR1H = 0xF8;
TMR1L = 0x30;
switch(select) {
case 0:
case 2:
case 4:
case 6:
case 8:
sendByte(*ptr2char++);
break;
case 1:
case 3:
case 5:
case 7:
case 9:
sendByte(0xFF);
break;
};
++select;
if((select == 0) || (select == 1) || (select == 3) || (select == 5) || (select == 7) || (select == 9)) {
CD4017_CLK = 1;
Delay_us(200);
CD4017_CLK = 0;
}
if(select == 10) {
CD4017_RST = 1;
Delay_us(200);
CD4017_RST = 0;
select = 0;
ptr2char = &display;
}
TMR1IF_bit = 0;
}
}
void main() {
CM1CON0 = 0x00;
CM2CON0 = 0x00;
SLRCON = 0x00;
ANSELA = 0x00;
ANSELB = 0x00;
ANSELC = 0x00;
TRISA = 0xC0;
TRISB = 0x03;
TRISC = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
ptr2char = &display;
InitTimer1();
while(1) {
display[0] = mask[number / 10000];
display[1] = mask[(number / 1000) % 10];
display[2] = mask[(number / 100) % 10];
display[3] = mask[(number / 10) % 10];
display[4] = mask[(number / 1) % 10];
}
}
display[0] = mask[number / 10000];
display[1] = mask[(number / 1000) % 10];
display[2] = mask[(number / 100) % 10];
display[3] = mask[(number / 10) % 10];
display[4] = mask[(number / 1) % 10];
//Timer1
//Prescaler 1:1; TMR1 Preload = 63536; Actual Interrupt Time : 2 ms
//Place/Copy this part in declaration section
void InitTimer1() {
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0xF8;
TMR1L = 0x30;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void sendByte(unsigned char byte) {
char i = 0, mask = 0x80;
for(i = 0; i < 8; i++) {
if(byte & mask)
DS = 1;
else
DS = 0;
SH_CP = 1;
Delay_us(50);
SH_CP = 0;
mask >>= 1;
}
ST_CP = 1;
Delay_us(50);
ST_CP = 0;
}
TMR1H = 0xF8;
TMR1L = 0x30;
sbit SH_CP at LATC0_bit;
sbit DS at LATC1_bit;
sbit ST_CP at LATC2_bit;
sbit CD4017_CLK at LATC3_bit;
sbit CD4017_RST at LATC4_bit;
switch(select) {
case 0:
case 2:
case 4:
case 6:
case 8:
sendByte(*ptr2char++);
break;
case 1:
case 3:
case 5:
case 7:
case 9:
sendByte(0xFF);
break;
};
++select;
if((select == 0) || (select == 1) || (select == 3) || (select == 5) || (select == 7) || (select == 9)) {
CD4017_CLK = 1;
Delay_us(200);
CD4017_CLK = 0;
}
if(select == 10) {
CD4017_RST = 1;
Delay_us(200);
CD4017_RST = 0;
select = 0;
ptr2char = &display;
}
if((select == 0) || (select == 1) || (select == 3) || (select == 5) || (select == 7) || (select == 9)) {
CD4017_CLK = 1;
Delay_us(200);
CD4017_CLK = 0;
}
when select is 0 (display[0] which is pointed to by the pointer *ptr2display is send to TPIC and then will give a clock to CD4017 and make its second pin ......
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?