Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -------------------------------------- Prototype Function --------------------------------------------------------------------------
- // Header File: busLeds.h
- #ifndef LEDSBUSBAR_H_INCLUDED
- #define LEDSBUSBAR_H_INCLUDED
- unsigned char turnOnLeds(unsigned char code, unsigned char stateLeds);
- unsigned char turnOffLeds(unsigned char code, unsigned char stateLeds);
- unsigned currentLedsState(unsigned char stateLeds);
- #endif // LEDSBUSBAR_H_INCLUDED
- //---------------------------------------- LEDs's Busbar Library ----------------------------------------------------------------------
- // .C File: busLed.h
- #include <stdio.h>
- #include "ledsBusbar.h"
- // Receives the parameter "code" which identify what Leds in busbar which will turn on.
- // For instance, code = 0xA2 will turn on the lEDs 7, 5, 1 and 0.
- // The parameter "stateBits" receive the previous state of LEDs busbar.
- unsigned char turnOnLeds(unsigned char code, unsigned char stateLeds){
- unsigned char getLeds;
- getLeds = stateLeds | code;
- return getLeds;
- }
- // Receives the parameter "code" which identify what LEDs's busbar which will turn off.
- // For instance, code = 0x55 will turn on the lEDs 6, 4, 2 and 0.
- // The parameter "stateBits" receive the previous state of LEDs's busbar.
- unsigned char turnOffLeds(unsigned char code, unsigned char stateLeds){
- unsigned char getLeds = 0x00;
- getLeds = stateLeds & (~code);
- return getLeds;
- }
- // Displays the current state of LEDs's busbar.
- unsigned currentLedsState(unsigned char stateLeds){
- unsigned char currentLeds;
- currentLeds = stateLeds;
- return currentLeds;
- }
- //------------------------------------------- Test File for this library -------------------------------------------------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include "ledsBusbar.h"
- int main(){
- int turnOff = 0, exit = 0;
- unsigned char codeOn = 0x00, codeOff = 0x00, leds = 0x00, stateLeds = 0x00;
- while (exit != 1){
- printf("Insert the hexadecimal code to turn on LEDs: ");
- scanf("%x",&codeOn);
- leds = turnOnLeds(codeOn, stateLeds);
- printf("%x\n",leds);
- printf("\nDo you want to turn off LEDs: Yes - Press 1 / No - Press any Character: ");
- scanf("%d", &turnOff);
- if (turnOff == 1){
- printf("Insert the hexadecimal code to turn off LEDs: ");
- scanf("%x",&codeOff);
- leds = turnOffLeds(codeOff, leds);
- printf("%x\n",leds);
- }
- stateLeds = currentLedsState(leds);
- printf("\n\nThe current leds state is %X.",stateLeds);
- printf("\n\nDo you want to continue? Yes - Press any Character / No - Press 1: ");
- scanf("%d",&exit);
- }
- return 0;
- }
- *** Note: This code display how to develop a code library which have three function:
- 1 - turnOnLeds - Receive two paramenters, code and stateLeds. "code" inserts a 8 bits value coded in hexadecimal format to
- turn on 8 leds in busbar. "stateLeds" receives the previous state of the LED busbar.
- 2 - turnOffLeds - Receive two paramenters, code and stateLeds. "code" inserts a 8 bits value coded in hexadecimal format to
- turn off 8 leds in busbar. "stateLeds" receives the previous state of the LED busbar.
- 3 - currentLedsState - Display the current state of led busbar.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement