PIC microcontroller modules and functions

Publisher:幸福时刻Latest update time:2015-03-26 Source: diangonKeywords:MCU  PIC16F616  CMOS Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  PIC16F616 is a 14-pin, 8-bit CMOS microcontroller. It uses a reduced instruction set with only 35 instructions. Due to the use of the Harvard bus structure with separate data bus and instruction bus, most instructions are single-cycle instructions except for a few instructions that are not single-cycle. This is conducive to improving the operating speed and execution efficiency of the microcontroller.

  The PIC16F616 microcontroller can be powered by a voltage between 2V and 5.5V. It has an internal RC oscillator, and the frequency can be configured to 8MHZ or 4MHZ. It can also use an external crystal oscillator to provide the clock. It has internally integrated hardware modules such as AD conversion and comparator, and also has functions such as power-on reset, undervoltage reset, watchdog, and code protection. Three timers, PWM generators, etc. can be programmed by the user. Let me introduce these modules and functions of the PIC microcontroller one by one.

  1. Memory

  PIC16F616 is divided into program memory and data memory. The size of program memory is 2048 words and the size of data memory is 128 bytes.

  The address 0000H in the program memory is the reset address. When the power is turned on or the watchdog timer is reset, the PC pointer will point to the reset address. Address 0004H is the interrupt address. When any interrupt occurs, the PC pointer will point to this address. Programs can be transplanted at addresses 0005H~07FFH.

  The data memory is divided into two parts, called bank0 and bank1, where the address range of bank0 is: 00H-7FH, and the address range of bank1 is 80H-FFH. General registers are placed in it, and bank0 and bank1 can be selected through the RP0 bit in the STATUSL register.

  When programming, please note that when the register you want to operate is in bank0, you must first select bank0 (set the RP0 position of the STATUS register to 0), and then operate the register you want to operate. When the register you want to operate is in bank1, you must first select bank1.

  If you want to define some variables, you can define them at the address starting from 20H in the data memory. The defined address range is 20H-7FH, which is usually enough.

  2. PIC input and output ports

  I encountered some problems when studying this part. The PIC microcontroller has few pins, most of which are multiplexed pins, such as AD, IO, comparator, external crystal oscillator, etc., so when configuring the port, you must know how to set each function to achieve it. In this section, I will talk about the setting of the general IO port.

  PIC16F616 has 12 IO ports, but one pin (RA3) can only be used as an input pin and cannot be used as an output. In addition, port A has the function of level change interrupt, while port C does not. Pay attention to this when designing.

  When setting up, you generally need to make the following settings:

  (1) Set whether the port is an analog port or a digital port. You can set it through the register ANSEL. For example, if you want to use AD, you need to set the corresponding pin as an analog input port.
  (2) If you choose a digital port, you will then need to set the direction of the port, whether it is input or output (except RA3). You can set it through the register TRISA (A port) or TRISC (C port).

  (3) To set the output level of the port, you can use the register PORTA (port A) or PORTC (port C).

  This is the general setting for IO ports, but it is not the complete setting. The following settings depend on whether it is port A or port C. For port A, it has several special functions: internal weak pull-up, level change interrupt, and edge interrupt of RA2/INT pin. If you want these functions, you need to set the corresponding registers.

  Weak pull-up setting: Weak pull-up is only valid when the pin is output. The weak pull-up of the corresponding pin can be set through the register WPUA. It is worth mentioning that if the weak pull-up is turned on, there will be excess current waste, which is not advisable for low-power design. However, if you are designing some keyboard circuits, for example, you can turn on the weak pull-up function, so there is no need to add a pull-up resistor in the keyboard circuit.

  Setting of level change interrupt: It can be set through register IOCA, but first the corresponding pin must be set as a digital port and in input state. At the same time, the REIE bit of register INTCON must be set to 1, and the general interrupt must be enabled (set the GIE bit of register INTCON). If the corresponding pin is set to have this function, when the pin level occurs, an interrupt will be generated, and some interrupt flags will be set (the RAIF bit of INTCON is set to 1), and the general interrupt GIE is set to 0. In the interrupt service program, the software must clear the RAIF bit and reset the GIE bit to continue to enable this interrupt.

  Edge interrupt setting of RA2/INT pin: First, set the corresponding pin to a digital port and input state, set the INTF bit of INTCON to 1, indicating that the int pin external interrupt is allowed, and the INTEGD bit of register OPTION_REG can be set to a rising edge interrupt or a falling edge interrupt. When an interrupt occurs, the INTF bit of INTCON is set to 1 and GIE is cleared. In the interrupt service program, the software must clear the INTF bit and reset the GIE bit to continue to enable this interrupt.

Keywords:MCU  PIC16F616  CMOS Reference address:PIC microcontroller modules and functions

Previous article:Implementation of software and hardware solutions for the automatic sun-chasing solar car
Next article:High-precision alcohol detector based on PIC microcontroller

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号