Napisałem dzisiaj sofcik do sterowania 7 segmentowym wyświetlaczem diodowym ze wspólną anodą. Wykorzystanie wygląda następująco:
Kod: Zaznacz cały
/**
*****************************************************************************
**
** File : main.c
**
** Abstract : main function.
**
** Functions : main
**
** Environment : Atollic TrueSTUDIO(R)
**
** Distribution: The file is distributed "as is", without any warranty
** of any kind.
**
** (c)Copyright Atollic AB.
** You may use this file as-is or modify it according to the needs of your
** project. This file may only be built (assembled or compiled and linked)
** using the Atollic TrueSTUDIO(R) product. The use of this file together
** with other tools than Atollic TrueSTUDIO(R) is not permitted.
**
*****************************************************************************
*/
#include <stdbool.h>
#include "mcu.h"
#include "ledmux/ledmux.h"
void SysTick_Handler(void);
volatile int timer100Hz;//timer programowy
int cnt;//jakis tam przykladowy licznik
int main(void)
{
SysTick_Config(SystemCoreClock/100);//niech systick generuje przerwanie co 10ms
ledmuxInit();//inicjalizacja multipleksu
__enable_irq();//upewniam sie, ze przerwania sa wlaczone
while (true)
{
if(!timer100Hz)//co 100ms inkrementuj licznik
{
if(++cnt > 9999)//zapetlam do 9999
{
cnt = 0;
}
ledmuxSetValue(0, (cnt%10));//ustawiam skrajnie prawa cyfre
ledmuxSetValue(1, (cnt/10)%10);
ledmuxSetValue(2, (cnt/100)%10);
ledmuxSetValue(3, (cnt/1000));//ustawiam skrajnie lewa cyfre
timer100Hz = 9;//nakrecam timer na 100ms
}
}
}
void SysTick_Handler(void)//obsluga przerwania od systicka
{
if(timer100Hz) timer100Hz--;
}
Jak widać obsługa jest bananalna... Jak i sam programik, no ale może komuś się przyda. Całość napisałem w Atollic True Studio. Zamieszczam również kompletny projekt dla tego IDE.
Aha, w pliku ledmux.h można sobie dowolnie przyporządkować piny sterujące wyświetlaczem.
Pozdrawiam.