![]() |
![]() |
| Mark's Project Pages/PIC Programming/Getting Started/Architecture | |
|
PIC Architecture: Programming a PIC processor is much easier if you have an understanding of the internal architecture, especially as it varies from the "normal" computer systems that you might already seen.
Von-Neumann Architecture: This, if you like, is the "normal" way to build a computer system. The address and data buses are common for all memory access. Program-code and data exist in the same memory range, along with any memory-mapped peripherals. This is the most common architecture in use… Pros:
Cons:
Harvard architecture: This architecture overcomes the memory bottle-neck by splitting the memory into instruction (code) and data areas. These are accessed via separate data and address busses… Pros:
Cons:
To summarise, programme memory is different to data memory - in the PIC16FXX series, the programme memory is 14 bits wide, whereas the data memory is a more "conventional" 8 bits wide. Remember - PICs are essentially an 8-bit processors. We'll see much more about this later.
Registers and Memory: Like any computer system, the PIC processor has a memory-map - as you can see, there are 256 different locations shown here - this suggests that 8 bits are required to address all the locations. The memory map has a 2-dimensional aspect - 7 bits will give you 0 to 127, moving you up and down the map, and the eighth bit will move you across the map, giving the total of 256 possible address locations. This is called paging or banking. As you'll see later, this 8th bit is extremely important - it's called RP0 and is contained in the STATUS register. A question to ponder - you'll note that the STATUS register is available on both "sides" of the map. Why is this essential?
Not shown is the Working Register, or "W". This is equivalent to the Accumulator on other CPU’s.
Using Peripherals: Before you can use a peripheral, you must configure it. Predictably, this varies in complexity, but can be very straightforward. For example: Port B - 8 bit wide bi-directional port: Individual bits of PORTB (address 05h) translate directly to physical pins on the IC. But, before the port can be used, you must program TRISB (the data-direction register). This tells the microcontroller whether the individual bits of PORTB are inputs or outputs. Example: Bits 0-3 are connected to LED's so we want them to be outputs. Bits 4-7 are connected to switches, so these need to be inputs. Setting a bit in TRISB makes the corresponding bit of PORTB an input. Therefore, TRISB needs to be programmed with 11110000 Having done this, we can now read and write to PORTB. Writing 15 ("00001111" in binary) to PORTB will light all the LED's. Clearing PORTB (by writing "00000000") will extinguish them. Reading PORTB and masking the lower bits will reveal the state of the switches.
Interrupts: These are a powerful way to ensure that a peripheral is able to demand
the attention of the CPU immediately!
Note: Red steps are automatically performed by the microcontroller. Some applications are entirely interrupt-driven, and do nothing until receiving an interrupt. In this case, there's no need to perform the optional steps. The PIC16F84 has 4 interrupt sources:
Typical examples include:
I feel that it is important to be aware of interrupts, and not to be frightened by them! Interrupts are essential to almost any real application, and are essential-learning!
This simple overview of the PIC architecture will hopefully help your understanding during the next few pages, where we start to write our first programme.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
©2004 Mark Hennessy
Contact Me | Site Map |
Disclaimer