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.
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
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- MSP430F5529 IO port pin interrupt study notes
- Circuit-level electrostatic protection design techniques and ESD protection methods
- [ESK32-360 Review] +TFT screen display function and expansion (3)
- Can the 7805 and 1117-5 power supplies be used within ±0.05?
- CC3200 Kit OURS-SDK-WFB_Exploration 4——FreeRTOS Run
- The microcontroller outputs PWM wave to control the load supply voltage 0-12V adjustable
- 【Insights】If you don’t plant flowers in your heart, weeds will grow
- [ESP32-Korvo Review] 1: ESP32-Korvo Audio Development Board Hardware Circuit Connection
- I would like to ask which manufacturers produce unipolar TMR tunneling effect switches. I only found MDT, and Magne does not have unipolar ones.
- Altium16.1 manufacturing output IPC-2581 and odb++ formats are not working