PEC short reference (simplified excerpt)
PEC stands for Portable Embedded Classes and is a class library for microcontroller applications.
All classes and templates intended for the application developer begin with the prefix Pec … The exclusive use of these library modules ensures the portability of the created application. The following short reference shows the most important PEC library blocks and their essential functions. A complete documentation of all PEC modules can be generated automatically from the respective class model.
The use of a PEC library block always follows the following pattern:
- Create a separate class for each system component
- Search for and assign a suitable PEC library block
- assign or configure the specific hardware used.
- create an instance of the system block
Example 1: An LED for the error display is provided on pin B0.
- Define the name of the system block and create the class: ErrorLED
- The library offers the high-level class template PecLed for such applications, assigning them
- the template must be supplemented with the resource pinB0
- the application needs an instance of the block, for example as an aggregation in the class Controller
Example 2: An RS232 terminal on UART0 of the controller is provided for the configuration of the embedded system.
- Define the name of the system block and create the class: Terminal
- The library offers the class template PecUart for such applications, assign them
- the template must be supplemented with the resource uart0xxx
- the application needs an instance of the block, for example as an aggregation in the class controller
NOTE: The identifiers of the hardware used are controller-specific!
elementary GPIO library blocks
PecPinInput «template» Parameters necessary pinXn, [pullUp]bool getState() //read current status from pin 0/1
PecPinOutput «template» Parameters necessary pinXnbool getState() // read current status from pin 0/1 void setState(bool) // write new status on pin 0/1 void on() // Pin turn on 1 void off() // Pin turn off 0 void toggle() // Pin toggle 0->1 / 1->0
PecPinInterrupt «template» Parameters necessary pinXn, [pullUp]bool getState() // read current status from pin 0/1 virtual void onPinEvent() // for overwriting, event handling function
pinXn «parameter» for templates#define %port% X #define %pin% n
pinPullUp «parameter» for templates#define %pinLevel% 1!
use case-oriented GPIO library blocks
PecPinOutputTimed «template» Parameters necessary pinXnvoid on(delay) // by x milliseconds delayed switch-on (10 ms steps) void off(delay) // by x milliseconds delayed switch-off (10 ms steps) void toggle(delay) // by x milliseconds toggle (10 ms steps) void pulse(delay,pulseMs) // ______|-------| void pulse(delay,hiMs,loMs,count) // ______|-------|_______|------| ... bool isBusy() // returns status, true = still busy
PecLED «template» Parameters necessary pinXnvoid on() // LED turn on void off() // LED turn off void toggle() // LED toggle void flash() // LED flashing once shortly void blink(code) // activates the blink code N, code=3 |||_|||_|||_... uint8_t getBlinkCode() // gives the current blink code void nextBlinkCode() // current blink code +1 void slowBlink() // blink slowly ... |__|__|__|__... void flicker() // blink quickly ... ||||||||||||... void dim() // shine dimmed by 50%
PecButtonClickAndHold «template» Parameters necessary pinXnbool isPressed() // returns the current status of the button true = pressed virtual void onClick() // to overwrite, event function on click virtual void onHoldStart() // to overwrite, event at start hold virtual void onHolding() // to overwrite, event every 10ms on hold virtual void onHoldEnd() // to overwrite, event at end of hold
elementary UART library blocks
PecUart «template» Parameters necessary baudrateXXX, uartN
void writeByte(byte) // sends an 8 bit value (byte) void writeString("String") // sends a text bool dataAviable() // checks for data at present uint8_t readByte() // reads a byte void write(WORD) // sends a 16 bit value void write(DWORD) // sends a 32 bit value void writeData(buffer,count) // sends n bytes from a buffer
uartEventRx «template» extension for template PecUart
void onEventRx(data) // Receive event // must be overwritten
baudrateXXXX «parameter» for template PecUart
#define %baud% xxx
elementary ADC library blocks
PecAdcSingle «template» Parameters necessary adcX, resolutionX, channelN,unsigned int getValue() // returns the current analog value
PecAdcChannel «template» Parameters necessary adcX, resolutionX, channelN,unsigned int getValue() // returns the last analog value of the channel
adcX «parameter» for template PecAdc…#define %adc% X // 0, 1, 2, ...
channelN «parameter» for template PecAdc…#define %channel% N // 0, 1, 2, ...
adcResolutionX «parameter» for template PecAdc…#define %resolution% X // 8, 10, 12
elementary TIMER library blocks
PecTimer «template» Parameters necessary timerN// basic class template for custom timers void configHz(hz) // initializes and starts the timer with x Hz void configMs(ms) // initializes and starts the timer with x mS void configUs(us) // initializes and starts the timer with x µS void stop() // stops the timer virtual onTimerEvent() // to overwrite, timer event function // If necessary, processing directly in the interrupt is also possible
PecCounterMs «template» Parameters necessary timerN// Stopwatch template, realizes time measurements in milliseconds void start() // the stopwatch starts at 0 unsigned int stop() // stops the stopwatch and returns the measured value unsigned int getCount() // returns the current value, stopwatch continues to run unsigned int reStart() // the stopwatch restarts at 0, returns the current value
PecCounterUs «template» Parameters necessary timerN// Stopwatch template, realizes time measurements in microseconds void start() // the stopwatch starts at 0 unsigned int stop() // stops the stopwatch and returns the measured value unsigned int getCount() // returns the current value, stopwatch continues to run unsigned int reStart() // the stopwatch restarts at 0, returns the current value
PecPwmChannel «template» Parameters necessary timerN und channelXvoid configHz() // configures the PWM frequency void setDuty(duty) // sets the pseudo-analog value 0 ... 1000 void start() // starts the PWM output void stop() // stops the PWM output
PecFrequencyChannel «template» Parameters necessary timerN und channelXvoid setHz(hz) // configures the output frequency void on() // starts the frequency output void off() // stops the frequency output
timerN «parameter» for templates PecTimer…#define %timer% n // 0, 1, 2, ...
channelX «parameter» for templates Pec…Channel#define %channel% X // A, B, C, ...
use case-oriented TIMER library blocks
PecSimpleSound «template» Parameters necessary timerN, channelXvoid play("SoundCode") // plays the tone sequence (melody) encoded in the string void stop() // stops the current sound output bool isPlaying() // checks for sound output is busy
// -------------------------------------------------------------- // Soundcodes: // Tone = letter, capital letter higher octave // cdefgah = tone // c´ = cis (des) =w // e´ = es (dis) =x // f´ = fis (ges) =y // a´ = as (gis) =z // b = (ais) // Tone = letter, capital letter higher octave // k...v = c...h include cis,es,fis,as,b // / from now 1 octave higher // \ from now 1 octave lower // , short pause 1/4 note length // . long pause 1/1 note length // Standard = 1/8 note // ^ from now on faster 2x (e.g. 1/16 note) // v from now on slower 1/2 (e.g. 1/4 note) // space = no meaning and no effect //----------------------------------------------------------------- // Example: a little nursery rhyme: speaker.play( "v d,e,f,g,aa,aa, h,h,h,h,aa,.. h,h,h,h,aa,.. g,g,g,g,ff,ff, a,a,a,a,dd" );