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:

  1. Create a separate class for each system component
  2. Search for and assign a suitable PEC library block
  3. assign or configure the specific hardware used.
  4. create an instance of the system block

Example 1: An LED for the error display is provided on pin B0.

  1. Define the name of the system block and create the class: ErrorLED
  2. The library offers the high-level class template PecLed for such applications, assigning them
  3. the template must be supplemented with the resource pinB0
  4. 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.

  1. Define the name of the system block and create the class: Terminal
  2. The library offers the class template PecUart for such applications, assign them
  3. the template must be supplemented with the resource uart0xxx
  4. 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!

PecPinInput «template» Parameters necessary pinXn, [pullUp]
bool getState()     //read current status from pin 0/1
PecPinOutput «template» Parameters necessary pinXn
bool 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!
PecPinOutputTimed «template» Parameters necessary pinXn
void 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 pinXn
void 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 pinXn
bool 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

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
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
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 channelX
void 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 channelX
void 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, ...
PecSimpleSound «template» Parameters necessary timerN, channelX
void 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" );

Go back