Ma 25 September 2017, 14:17

File #350

The external button on PA7 toggle the LED on the external LED connected to PA6.
The onboard LED 1 (PB5) can be toggled using the onboard User button (PB10).

C code -
  1. #include "gpio.c"
  2.  
  3.  
  4. int main(void){
  5.   GpioMode(GPIOA, 1<<7, MODE_IPU);         // Config A7 (pin 17) as input with internal pull-up resistor
  6.   GpioMode(GPIOA, 1<<6, MODE_PP);           // Config A6 (pin 16) as output (PP = Pusp-Pull), if no speed is defined: default = SPEED_50MHz
  7.  
  8.   GpioMode(GPIOB, 1<<10, MODE_IPU);         // Config B10 (pin 21) as input with internal pull-up resistor
  9.   GpioMode(GPIOB, (1<<5 | 1<<8 | 1<<9), (MODE_PP | SPEED_50MHz));   // Config B5 (pin 41), B8 and B9 as output (PP = Pusp-Pull), Speed = SPEED_50MHz
  10.  
  11.   sbi(PORTB, 8); // Set PB8 high, 3,3V: Led 2 is turned on
  12.   sbi(PORTB, 9); // Set PB9 high, 3,3V: Led 3 is turned on
  13.  
  14.   // infinite loop
  15.   while(1){
  16.     if(rbi(PINA, 7)){     // Read Bit 7 from PINA
  17.       sbi(PORTA, 6);     // Set Bit 6 from PORTA
  18.     }
  19.     else{
  20.       cbi(PORTA, 6);     // Clear Bit 6 from PORTA
  21.     }
  22.  
  23.     if(rbi(PINB, 10)){     // Read Bit 10 from PINB
  24.       sbi(PORTB, 5);     // Set Bit 5 from PORTB
  25.     }
  26.     else{
  27.       cbi(PORTB, 5);     // Clear Bit 5 from PORTB
  28.     }
  29.   }  
  30. }
Nog geen reacties.
Laatste wijziging: Zo 20 Februari 2011, 15:41