Datasheet
Page 14
Page 15
Time has come to do some coding. First thing 
we need to do is to disable analog function of 
PORTBpins,sotheyactasdigitalonly:
Now  we  have  to  initialize  PORTB  to  act  as 
digital output. TRISB register, associated with 
PORTB, is used to set whether each pin acts 
as input or output.
LATB  register is  used  instead  of PORTB  for 
digital  output.  We can  now initialize it  with 
logiczerosoneverypin:
Finally, in a while  loop  we  will  toggle  the 
PORTB  value,  and  put  a  1000  ms  delay,  so 
theblinkingisnottoofast(seeFigure 4-1).
program LedBlinking;
begin
 // Congure analog pins as digital I/O
 AD1PCFG := 0xFFFF;
 // set PORTB to be digital output
 TRISB := 0;
 // Turn OFF LEDs on PORTB
 LATB := 0;
  while TRUE do
 begin
  // Toggle LEDs on PORTB
 LATB := not LATB;
 // Delay 1000 ms
 Delay_ms(1000);
 end;
end.
// set PORTB to be digital output
TRISB := 0;
// Congure AN pins as digital I/O
AD1PCFG := 0xFFFF;
// Turn OFF LEDs on PORTB
LATB := 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
LedBlinking.mpas - source code
4. Code Example
Figure 4-1: Complete source code of the PORTB LED blinking










