Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. class gpioTask : public scheduler_task
  2. {
  3. public:
  4. gpioTask(uint8_t priority) :
  5. scheduler_task("gpio", 512, priority)
  6. {
  7. /* Nothing to init */
  8. }
  9.  
  10. bool init(void){
  11. LPC_PINCON->PINSEL2 &= ~((1<<28)|(1<<29)); // Set SW1.14
  12. LPC_PINCON->PINSEL2 &= ~((1<<8)|(1<<9)); // Set LED 1.4
  13.  
  14. LPC_GPIO1->FIODIR &= ~(1 << 14); // make input sw 0
  15. LPC_GPIO1->FIODIR |= (1 << 4); // make output led 1
  16.  
  17. LPC_PINCON->PINSEL0 &= ~((1<<0)|(1<<1)); // set GPIO 0.0 input sw
  18. LPC_PINCON->PINSEL0 &= ~((1<<2)|(1<<3)); // set GPIO 0.1 output led
  19.  
  20. LPC_GPIO0->FIODIR &= ~(1 << 0);; // make input sw by setting 0
  21. LPC_GPIO0->FIODIR |= (1 << 1); // make output led by setting 1
  22.  
  23. return true;
  24. }
  25.  
  26.  
  27. bool run(void *p)
  28. {
  29. //Onboard LED/Switch
  30. if(LPC_GPIO1->FIOPIN & (1 << 14) ){
  31. LPC_GPIO1->FIOCLR = (1 << 4 ); // LED On
  32. }
  33.  
  34. else{
  35. LPC_GPIO1->FIOSET = (1 << 4 ); // LED Off
  36. }
  37.  
  38. //External Switch/LED
  39. if(LPC_GPIO0->FIOPIN & (1 << 0) ) { // check if P0.0 is on
  40. //Active High Config
  41. LPC_GPIO0->FIOSET = (1 << 1 ); // Button Pressed LED ON
  42. }
  43.  
  44. else{
  45. LPC_GPIO0->FIOCLR = (1<< 1); // Button Not Pressed LED OFF
  46. }
  47. return true;
  48. }
  49. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement