Chapter 8

Porting Code to Other Microcontrollers

The programs we have done so far have used the PIC18F1220 and we started off by using the header of Figure 3.6 redrawn below.

The Header Code

1.// Name.c by DW Smith, dd/mm/yyyy
2.#include <p18f1220.h>
3.#pragma config WDT=OFF, OSC=INTIO2, PWRT=ON, LVP=OFF, MCLRE=OFF
4.#include <delays.h>
5.
6.void main (void)
7.{
8.   //SET UP
9.   // OSCCON defaults to 31 kHz. So no need to alter it.
10.   ADCON1=0×7F;//all IO are digital or 0b01111111 in binary
11.   TRISA=0b11111111;   //sets PORTA as all inputs
12.   PORTA=0b00000000;   //turns off PORTA outputs
13.   TRISB=0b00000000;   //sets PORTB as all outputs
14.   PORTB=0b00000000;   //turns off PORTB outputs, good start position
15.
16.while (1)
17.  {
18.
19.
20.
21. ...

Get PIC Projects and Applications using C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.