Datasheet
Programming PIC Microcontrollers in BASIC - mikroElektronika
 end if
 end if
 end if
end sub
main:
 TRISB = %00111111 ' Pins RB6 and RB7 are output
 OPTION_REG = %10000000 ' Turn off pull-up resistors
 ' and set interrupt on falling edge
 ' of RB0 signal
 INTCON = %10010000 ' Enable external interrupts
 PORTB = 0 ' Initial value on PORTB
eloop: ' While there is no interrupt, program runs in 
endless loop:
 LED_run = 1 ' LED_run is on
 LED_int = 0 ' LED_int is off
goto eloop
end.
Now, what happens when we push the button? Our interrupt routine first analyzes the interrupt by checking flag bits with 
couple of if..then instructions, because there are several possible interrupt causes. In our case, an external interrupt 
took place (pin RB0/INT state changes) and therefore bit INTF in INTCON register is set. Microcontroller will change 
LED states, and provide a half second delay for us to actually see the change. Then it will clear INTF bit in order to 
enable interrupts again, and return to executing the main program.
In situations where microcontroller must respond to events unrelated to the main program, it is very useful to have an 
interrupt service routine. Perhaps, one of the best examples is multiplexing the seven-segment display – if multiplexing 
code is tied to timer interrupt, main program will be much less burdened because display refreshes in the background.
6.2 Internal AD Converter
A number of microcontrollers have built in Analog to Digital Converter (ADC). Commonly, these AD converters have 8-
bit or 10-bit resolution allowing them voltage sensitivity of 19.5mV or 4.8mV, respectively (assuming that default 5V 
voltage is used).
The simplest AD conversion program would use 8-bit resolution and 5V of microcontroller power as referent voltage 
(value which the value "read" from the microcontroller pin is compared to). In the following example we measure voltage 
on RA0 pin which is connected to the potentiometer (see the figure below).
http://www.mikroelektronika.co.yu/english/product/books/picbasicbook/06.htm (3 sur 12)05/11/2004 02:26:24










