hemnath
Advanced Member level 3
- Joined
- Jun 24, 2012
- Messages
- 702
- Helped
- 61
- Reputation
- 120
- Reaction score
- 57
- Trophy points
- 1,308
- Location
- Chennai
- Activity points
- 6,589
hi,
I'm using PIC18LF2520. Internal oscillator: 1Mhz, CCS C Compiler
I'm using charlieplexing method to display the numerals in the Seven Segment display (SSD). SSD is of type Common Anode.
Below is the sample Code:
Problem noticed: I want to display 1234 in display. But the LED's are blinking at the fast rate. I have set up the interrupt to 1ms.
Does anyone knows any other method to use charlieplexing?
Please help
I'm using PIC18LF2520. Internal oscillator: 1Mhz, CCS C Compiler
I'm using charlieplexing method to display the numerals in the Seven Segment display (SSD). SSD is of type Common Anode.
Below is the sample Code:
HTML:
#include "18F2520.h"
#fuses INTRC_IO
#use delay(clock=1000000)
#use fixed_io(b_outputs=PIN_B4,PIN_B5,PIN_B6,PIN_B7)
const char DIGIT_ZERO[] = {
// gfedcba
0b11111110, // a
0b11111101, // b
0b11111011, // c
0b11110111, // d
0b11101111, // e
0b11011111, // f
0b11111111 // g
};
const char DIGIT_ONE[] = {
// gfedcba
0b11111111, // a
0b11111101, // b
0b11111011, // c
0b11111111, // d
0b11111111, // e
0b11111111, // f
0b11111111 // g
};
const char DIGIT_TWO[] = {
// gfedcba
0b11111110, // a
0b11111101, // b
0b11111111, // c
0b11110111, // d
0b11101111 // e
0b11111111, // f
0b10111111 // g
};
const char DIGIT_THREE[] = {
// gfedcba
0b11111110, // a
0b11111101, // b
0b11111011, // c
0b11110111, // d
0b11111111, // e
0b11111111, // f
0b10111111 // g
};
const char DIGIT_FOUR[] = {
// gfedcba
0b11111111, // a
0b11111101, // b
0b11111011, // c
0b11111111, // d
0b11111111, // e
0b11011111, // f
0b10111111 // g
};
const char DIGIT_FIVE[] = {
// gfedcba
0b11111110, // a
0b11111111, // b
0b11111011, // c
0b11110111, // d
0b11111110, // e
0b11011111, // f
0b10111111 // g
};
const char DIGIT_SIX[] = {
// gfedcba
0b11111110, // a
0b11111111, // b
0b11111011, // c
0b11110111, // d
0b11101111, // e
0b11011111, // f
0b10111111 // g
};
const char DIGIT_SEVEN[] = {
// gfedcba
0b11111110, // a
0b11111101, // b
0b11111011, // c
0b11111111, // d
0b11111111, // e
0b11111111, // f
0b11111111 // g
};
const char DIGIT_EIGHT[] = {
// gfedcba
0b11111110, // a
0b11111101, // b
0b11111011, // c
0b11110111, // d
0b11101111, // e
0b11011111, // f
0b10111111 // g
};
const char DIGIT_NINE[] = {
// gfedcba
0b11111110, // a
0b11111101, // b
0b11111011, // c
0b11111111, // d
0b11111111, // e
0b11011111 // f
0b10111111 // g
};
unsigned int16 value = 0, temp_value = 0, value1 = 0, count = 0;
unsigned int16 increment = 0, DIGIT_VALUE = 0;
int1 DIGIT_FLAG = 1;
int1 UP_FLAG = 1;
unsigned int disp_value1, disp_value2, disp_value3, disp_value4;
unsigned int16 DIGIT_VAL;
void display_value();
void digit(int16 DIGIT_VALUE);
void segment(int16 digit);
#INT_TIMER1
void timer1_isr()
{
if(interrupt_active(INT_TIMER1))
{
count++;
if(count > 6)
{
INCREMENT++;
count = 0;
}
if(INCREMENT == 0)
{
output_b(0b00010000); // 1st digit
DIGIT(disp_value4); //
}
if(INCREMENT == 1)
{
output_b(0b00100000);
DIGIT(disp_value3);
}
if(INCREMENT == 2)
{
output_b(0b01000000);
DIGIT(disp_value2);
}
if(INCREMENT == 3)
{
output_b(0b10000000);
DIGIT(disp_value1);
}
if(INCREMENT > 3)
{
INCREMENT = 0;
}
set_timer1(0xFF05); // 1ms for 1Mhz
clear_interrupt(INT_TIMER1);
}
}
#INT_EXT
void ext_interrupt_isr()
{
DIGIT_FLAG = 0;
}
#INT_EXT1
void ext_interrupt_isr1()
{
UP_FLAG = 0;
}
void main()
{
set_tris_a(0xFF);
set_tris_b(0x00);
setup_comparator(NC_NC_NC_NC);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
set_timer1(0xFF05); // 1ms for 1Mhz
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT1);
#priority TIMER1, EXT, EXT1
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
count=0;
INCREMENT = 0;
DIGIT_VALUE = 0;
DIGIT_VAL = 1234;
disp_value1 = (DIGIT_VAL%10);
disp_value2 = ((DIGIT_VAL/10)%10);
disp_value3 = ((DIGIT_VAL/100)%10);
disp_value4 = ((DIGIT_VAL/1000)%10);
while(1)
{
// To display 1234 in Seven segment display
}
}
void DIGIT(int16 DIGIT_VALUE)
{
switch (DIGIT_VALUE)
{
case 0: output_a(DIGIT_ZERO[count]);
break;
case 1: output_a(DIGIT_ONE[count]);
break;
case 2: output_a(DIGIT_TWO[count]);
break;
case 3: output_a(DIGIT_THREE[count]);
break;
case 4: output_a(DIGIT_FOUR[count]);
break;
case 5: output_a(DIGIT_FIVE[count]);
break;
case 6: output_a(DIGIT_SIX[count]);
break;
case 7: output_a(DIGIT_SEVEN[count]);
break;
case 8: output_a(DIGIT_EIGHT[count]);
break;
case 9: output_a(DIGIT_NINE[count]);
break;
}
}
Does anyone knows any other method to use charlieplexing?
Please help