Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: freedom_green_led.c
- * Purpose: Main process
- *
- */
- #include "common.h"
- #include "ports.h"
- #include "isr.h"
- /* void enable_sistick(void) {
- SYST_RVR = 48000000; //0x00493E00; // SysTick Reload Value Register, 100ms
- SYST_CVR = 0x00000000;
- SYST_CSR = SysTick_CSR_ENABLE_MASK |
- SysTick_CSR_TICKINT_MASK |
- SysTick_CSR_CLKSOURCE_MASK;
- } */
- int state = 5;
- int bauncCounter = 0;
- int bauncLast = 0;
- int debauncer(int btn)
- {
- if(!btn) {
- bauncCounter = 0;
- bauncLast = 0;
- }
- if(!bauncLast & btn) {
- if(bauncCounter < 0xff) {
- bauncCounter++;
- } else {
- bauncLast = 1;
- return 1;
- }
- } else {
- bauncCounter = 0;
- return 0;
- }
- }
- void on(void)
- {
- }
- void off(void)
- {
- }
- int counter = 0;
- void systick_isr(void)
- {
- if (counter < 10) {
- counter++;
- } else {
- counter = 0;
- on();
- }
- if (counter == state) {
- off();
- }
- }
- int main (void)
- {
- printf("\n\n\rRunning the blinky project.\n\r");
- initLed('R');
- initLed('g');
- initPort('C', 3, 0);
- initPort('C', 12, 0);
- systick_init(4800); // 48 000 000 / 4 800 = 10 000
- for (;;)
- {
- int pb = debauncer(readPort('B', 3));
- int mb = debauncer(readPort('B', 12));
- if (state < 10) {
- state -= mb;
- } else if (state > 0) {
- state += pb;
- } else {
- state += pb;
- state -= mb;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement