Mikroelektronika MIKROE-350 Ficha De Dados

Página de 526
477
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Example
PORTC is inverted on every PORTB.B0 one-to-zero transition :
program Button
' Button connections
dim Button_Pin as sbit at PINB.B0       
dim Button_Pin_Direction as sbit at DDRB.B0 
' End Button connections
dim oldstate as bit    
' Old state flag
main
Button_Pin_Direction = 0          ' Set Button pin as input
DDRC  = 0xFF                      ' Configure PORTC as output
PORTC = 0xAA                      ' Initial PORTC value
oldstate = 0                      ' oldstate initial value
while TRUE 
if (Button(1, 1) = 1)           ' Detect logical one
oldstate = 1                  ' Update flag
end if
if 
(oldstate and Button(1, 0)) then ' Detect one-to-zero
transition
PORTC = not PORTC                ' Invert PORTC
oldstate = 0                     ' Update flag
end if  
wend    
' Endless loop
end.