neomus
Joined: 07 Oct 2011 Posts: 2
|
RTOS for multiplexing |
Posted: Fri Oct 07, 2011 6:38 am |
|
|
Hi
I am trying to multiplex a 7 segment led display(2 digit) using RTOS.
MCU - PIC16f628a
A2 and A3 are driving the common cathode of the display. A0 is connected to a button which output the variable "count" to portb when pressed.
portb is connected to segments
Problem is when i power up the circuit sometime A2 and A3 blinks together
sometime A2-ON, A3-OFF (A2-OFF, A3-ON) which is okay for the application. Please someone advise me.
Code: | #include <16f628a.h>
#use delay (int=4000000)
#use rtos(timer=0, minor_cycle=1ms)
int count;
unsigned int var1=0;
//
#task(rate=200ms, max=1ms)
void live1()
{
output_toggle(PIN_A2); // Toggle RA2
}
//
#task(rate=200ms, max=1ms)
void live2()
{
output_toggle(PIN_A3); // Toggle RA3
}
// Declare TASK "Display" - called every 10ms
//
#task(rate=10ms, max=1ms,queue=1)
void Display()
{
if(rtos_msg_poll() > 0) // Is there a message ?
{
output_b(rtos_msg_read()); // Send to PORTB
}
}
//
// Declare TASK "Generator" - called every millisecond
//
#task(rate=1ms, max=1ms)
void Generator()
{
count++; // Increment count
if ((input(PIN_A0) == 1)&& (var1 ==0)) // Switch pressed ?
{
var1 =1; //switch debounce
rtos_msg_send(Display,count); // send a message
}
else if ((input(PIN_A0)==0) && (var1 ==1))
var1 = 0;
}
void main()
{
set_tris_a(0x03); // A0 and A1 input
set_tris_b(0x00); /portb is output
output_b(0x00); //clear portb
output_a(0x04); //to make sure A2 and A3 are not blink together
rtos_run();
}
|
|
|