[ Pobierz całość w formacie PDF ]
.All instructions in the PIC16 series use 14-bitinstructions.The reset vector points to address 0000H and the interrupt vector is0004H so address locations 0005H to 03FFH are available for us tohold our programs.Data memoryThe data area is subdivided into two areas, the FSR (file select register)and the GP (general purpose registers) as shown in Figure 15.8.Figure 15.8Register file map212 Microcontrollers and how to use themThe SFR (special function register)This register controls the operation of the CPU and involves suchthings as the input and output ports, EEPROM address and data, timer,program counter and that sort of housekeeping.All the register files are 8-bits wide and are arranged in two bankscalled bank 0 and bank 1.We have to instruct the microcontroller asto which bank is to be used and this is done by using specialinstructions to access some of the page 1 registers.Those accessibleare indicated in Figure 15.8.Microchip Technology are planning toremove the choice of using the OPTION and the two TRIS registersand suggest that the STATUS register is used instead.This does notaffect the use with this chip but it will ensure that upgrading in thefuture will not require any modifications to the software.I/O (input/output) portsAll outputs can source or sink 25 mA and can therefore powersignificant external circuits without further power amplifiers beingrequired.Sinking means that the load is connected between thepositive Vcc supply and a low voltage output at the port and sourcingis connecting the load between a positive output on the pin to theground.PortA and TRISA registersPortA is a 5-bit wide bi-directional port, each line being individuallycontrolled so some of the lines can be inputs whilst the others areoutputs.The choice of input or output is made by loading a 0 (output)or a 1 (input) into the appropriate bit of the data direction registerTRISA.In common with other devices, when it first starts at power-on, the portis set as an input.This provides a safer option that running the risk ofrandom information being sent out to whatever it is connected to.PortB and TRISB registersPortB is a 8-bit wide bi-directional port, each line being individuallycontrolled using TRISB in the same manner as in PortA.Each of thePortB pins have a weak internal pull-up which can be switched on oroff by the RBPU of the option register.The pull-ups are disabled whenthe port is being used as an output and also during power switch-on.Any of the Pins RB4 RB7 that just happen to be configured as an inputhave an interrupt-on-change feature that can be useful.If any one ormore of these pins have changed logic state since they were last read,it causes an RB port change interrupt.This interrupt can be used towake the microcontroller from its  sleep mode.213 Introduction to Microprocessors and MicrocontrollersStatus registerThis is very similar to the one we met when looking at the Z80 inChapter 8.The bits are:Bit 0 is the C(carry/borrow) bit.1 = a carry out from the MSB (mostsignificant bit) of the result otherwise it is cleared to zero.For  borrowthe values are reversed.Subtraction is carried out using thetwo s-complement method that we met in Chapter 4.Bit 1 reflects the carry situation that last occurred from the 4th bit of theresult.This is also called the half-carry bit.Bit 2 is the zero flag.It is set to ONE when the result of the last arithmeticor logic operation is ZERO.Be careful not to misread this.Bit 3 goes to 0 after running the SLEEP instruction.Bit 4 goes to 0 when a watchdog time-out has occurred.Bit 5 is used to select between the two memory banks.It is cleared to0 to access Bank 0 and set to 1 if we need access to Bank 1.Bit 6 and bit 7  not used.It will be used in the future so by programmingthem for 0, future compatibility will be assured.This may save a lot oftime if our program is used on an upgraded version.Option registerAs the name suggests, it offers a series of options.One example is thecontrol of the prescaler.The PrescalerTwo functions are affected by the prescaler, they are the timer, TMR0(timer zero) and the watchdog timer.Each of these circuits provides anoutput pulse after the count overflows and restarts from zero.In thecase of the watchdog, the time interval is about 18 ms.If a longer timeinterval is needed, we have three alternatives.We can simply switchthe watchdog off but, of course, we lose the benefits of the watchdogif the microcontroller gets caught in a loop [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • wpserwis.htw.pl