You are on page 1of 17
# ECE 517 LECTURE NOTE ARDUINO AND PIC MICROCONTROLLER PIC Microcontroller: The PIC microcontroller is a family of microcontrollers manufactured by microchip this means that the microcontroller IC is a product of microchip. If you analyze this name PIC we get P for peripheral, Ifor the interface, and C for the controller. So full meaning of PIC is the peripheral interface controller. Now I will give you an example so that you can understand the main reason behind the PIC name. So, first of all, suppose you want to turn on and tum off the lights and fans using the computer keyboard buttons “A” and “B” but how is this possible because the keyboard is an analog device and the computer is a digital device this is possible if you use a third device as a unit and this device is a PIC microcontroller. This device acts as a unit between the keyboard and computer. The pic microcontroller connects and controls the computer and keyboard with the position between them, First, we will see the family members of PIC microcontrollers the PIC microcontroller product family currently consists of 6 groups. Now I will tell you the names of six groups of microcontrollers. So first one is PIC 10FXXX this microcontroller can take 12-bit program work, the second one is PIC 12CXXX or PIC 12FXXX this microcontroller has 12 or 14-bit program memory, the third one is PIC 16C5X this microcontroller also can take PIC Program word, the fourth one is PIC 16CXXX or PIC 16FXXX microcontroller of this model can take a 14-bit program, the fifth one is PIC. 17CXXX and this microcontroller can take 16-bit programmer and the last one is PIC 18CXXX or PIC 18FXXX and this microcontroller can take 16-bit programmer. This XXX means you can use three numbers in the XXX space as the name of the model serial. Now I introduce you to the PIC 16FXXX microcontrollers’ family members. so the first IC is PICIOF84 or PICIGF84A this kind of IC has 18 pins then the second one is PICI6F8 and this also has 18 pins then the third one is PICI6F72 or 16£73 and this IC has 28 pins and the fourth ic is PIC16F877 or PICL6F877A and this has 40 pins. This IC is currently the largest IC in this PIC series, Pin Description: Now we will discuss the pin description of PICI6F877A. It is CMOS flash-based 8-bit microcontroller based on the microchips powerful PIC architecture. Tt has a total number of 40 pins out of which Port A has 6 pins, Port B, Port C, and Port D has 8 Pins each, and port E has 3 pins. So from Port A to Port B, we have a total of 3 input and output pins. After that, we have two pins of VDD, two pins for VSS, one pin for MCLR which is the master clear pin of the microcontroller. Then we have one pin for OCS1 and one pin for OCS2 where the OCS1 is the oscillator input and OCS2 is the Oscillator output, These are the pins where the crystal oscillator is connected. The PIC microcontroller also consists of special pins like the RX and TX. The RX is serial input and TX is serial output, Together these two pins ere used for asynchronous serial communication with the serial devices. After that, we have SCL and SDA pins where the SDA is serial data and SCL is a serial clock. These two pins from the two- wire I2C or integrated circuit of the PIC microcontroller. Then we have the four pins SD0, SDI, SCK, and the SS Pin, These four pins form the SPI or serial peripheral interface of the pic microcontroller. Now from ANO to AN7, we have 10 bit ADC the analog to digital converter. Then we have RBO which is the external interrupt pin for the pic microcontroller. CCP! and CCP2 are the two PWM modules. PCO to PC7 we have the parallel slave port with external real write and CS control. The parallel slave port is 8 bit. PIC microcontroller features: “7 ao Operating Frequency 48 MHz Program memory 32Kb Program memory (instruction) 16Kb L a a “ - — —-- one T D Kb. — Data memory ae Data EEPROM oe Interrupt sources 20 170 pons Port A, B,C, D, E Timers 4 PWM modules 1 Serial communication MSSP, Enhanced USART usB 1 L | ssn port Yes 10 Bit analog to digital module Comparators 13 input channels An atmega328. microcontroller is manufactured by ATMEL making you input voltage of ‘round 7 volt or 12 volts to this port. The operating voltage of the microcontroller is 5 volt it has CPU speed of 16 megahertz, There are analog inputs or output pins that are 6 in number. ‘There are the 14 digital input/output pins out of which 6 can be used for pulse width modulation ‘The major feature of this pulse width modulation is it can be uset-to vary the intensity or te speed it has a EEPROM of 1 kb SRAM of 2 kb flash memory of 32kb'which can be used to store the program or load the program, UART universal a synchronous receiving transmission of 1 USB type is regular it has a reset pin which when pressed the program is going to start from the first line. The pin numbers A4 and AS which are analog pins has SDA and SCL input which can be used to receive a real-time clock configuration when used with ds1307. The digital pins 0 and 1 are used for serial communication 0 for receiving and 1 for transmission pin number 2 and 3 which is digital can also be used for interrupts purpose. Atmega 328P description: is low power CMO: : : nanan ata out of which 14 are digital output input pins from DO to D13. It also pins § 8 bit microcontroller based on enhanced AVR architecture. It ns ares ae om A0 to AS these form the analog to digital converter of the atmega328. has 6 ADC channels fr i 12. It also has 6 pwm channels and two pins for XTALI and XTA\ Data memory Data EEPROM Interrupt sources ‘Streaming parallel port 10 Bit analog to digital module Comparators Packages, Arduino: An atmega328_ microcontroller is manufactured by ATMEL mi as 7 vott or 12 volts to this port. The operating voltage of the microcontroller is 5 volt it hes aCPl U speed of 16 megahertz. There are analog inputs or output pins that are 6 in number. aking you input voltage of Hino okay ni ‘The atmega328 also has some special pins like SCK which stands for serial clock, MISO stands for master input slave output, MOSI stands for master output slave input, SS stands for slave Select. Together these four pins form serial peripheral interface of the atmega328, After that we have SCL and SDA which are the serial clock and serial data which form the I3C ort of the atmega328, The operating voltage of this microcontroller ranges from 1.8V to $.SV but typically wwe used SV for this purposes. It can be combined with 16 Mhz Crystal oscillator along with 22pF capacitor to form the erystal oscillator circuit. We 32 KB of flash memory, 2KB of SRAM and about of 1 KB EEROM, Arduino features: Operating Voltage 3V Input Voltage 7-12V Digital 1/0 pins 14 Analog input pins ; DC current per VO 40 mA DC current for 3.3V pin 50 mA 32Kb Flash memory | SRAM, a 2Kb 1KB (om Clock Speed 16 MHz _ ‘Timers, 4 | pwn modules ‘communication Serial, UART, TTL, SPI Differences between PIC Microcontroller and Arduino First of all, Arduino is not actually a microcontroller it is a microcontroller board or development board. It has an AVR atmega328 microcontroller in it. PIC microcontroller is a family of microcontrollers made by microchip. They are mostly sold as chips and we need to put them on a circuit board by a sap socket and a few cables also external programmers like pick it 2 or pick 3 are needed to program the microcontroller using MPLAB X IDE. The software has less libraries 4s compared to Arduino UNO.Arduino UNO is however is very cost-effective compared to PIC and it comes under open-source hardware cross platforms are also available as you can program it on Windows Linux and Mac while most of the pic microcontrollers are only programmable in Windows setup. The Ardino can be connected to the computer using a USB cable, Arduino has anoihg Tucrocontroller that acting as a programmer therefore it does not require an extemal device fy Programming. The programming environment is very easy to use even for beginners th library of examples is also present in IDE. So all you need is a USB eable Arduino software and Arduino board.The PIC microcontroller is a program and developed using MPLAB X software The MPLAB X software is free tool such as Arduino IDE but you have to pick the compiler Yourself. We need more tools for the pic microcontroller, While in Arduino we only need an Arduino board, Arduino software, and USB cable, Sometimes we do not need a USB cable because the software is in it. Introduction to the Arduino Programming Language How can we write programs to an Arduino board? Arduino, natively, supports a language that we call the Arduino Programming Language, or Arduino Language. ‘This language is based upon the Wiring development platform, which in tum is based upon Processing, which if you are not familiar with, is what p5,is(JavaScript library for creative coding) is based upon. It’s a long history of projects building upon other projects, in a very Open Source way. The Arduino IDE is based upon the Processing IDE, and the Wiring IDE which builds on top of it. When we work with Arduino we commonly use the Arduino IDE (Integrated Development Environment), a software available for all the major desktop platforms (macOS, Linux, Windows), which gives us 2 things: a programming editor with integrated libraries support, and a way to easily compile and load our Arduino programs to a board connected to the computer. The Arduino Programming Language is basically a framework built on top of C++. You can argue that it’s not a real programming language in the traditional term, but I think this helps avoiding confusion for beginners. A program written in the Arduino Programming Language is called sketch. A sketch is normally saved with the .ino extension (from Arduino). The main difference from “normal” C or C++ is that you wrap all your code into 2 main functions. You can have more than 2, of course, but any Arduino program must provide at least those 2. One is called setup(), the other is called loop). The first is called once, when the program starts, the second is repeatedly called while your program is running. We don’t have a main() function like you are used to in C/C++ as the entry point for a program. Once you compile your sketch, the IDE will make sure the end result is a correct Crt program and will basically add the missing glue by preprocessing it. Everything else is normal C++ code, and as C++ isa superset of C, any valid Cis also valid Arduino code. One difference that might cause you troubles is that while you can spawn your program over multiple files, those files must all be in the same folder. Might bea deal breaking limitation if your program will grow very large, but at that point it Seal be easy to move to a native C+ setup, which is possible. Part of the Arduino Programming Language is the built-in libraries that allow you to easily integrate with the functionality provided by the Arduino board. Your first Arduino program will surely involve making a led turn on the light, then a off. To do so, use the pinMode(), delay() and digital Write() functions, ith some constants like HIGH, LOW, OUTPUT. a Here is the code: #define LED_PIN 13 void setup() { // Configure pin 13 to be a digital output pinMode(LED_PIN, OUTPUT); i void loop() { // Turn on the LED digital Write(LED_PIN, HIGH); /] Wait 1 second (1000 milliseconds) delay(1000); 1 Tum off the LED digitalWrite(LED_PIN, LOW); Wait 1 second delay(1000); } This is all part of the Arduino Programming Language, or we'd better call it suite or library. Support for other language uage and IDE to program an Arduino. Projects exist, among others, to let you run Node,js code on it using the Johnny Five project, Python code using pyserial and Go code with Gobot, but the Arduino Programming Language is predominantly used, since it’s the native and canonical way to work with these devices. You are not limited to using this langi The Arduino Programming Language Built-in constants Arduino sets two constants we can use: HIGH equates to a high level of voltage, which can differ depending on the hardware (@2V on 3.3V boards like Arduino Nano, >3V on SV boards like Arduino Uno) LOW equates to a low level of voltage. Again, the exact value depends on the board used ‘Then we have 3 constants we can use in combination with the pinMode() function: + INPUT sets the pin as an input pin * OUTPUT sets the pin as an output pin . + INPUT_PULLUP sets the pin as an internal pull-up resistor + . f the ‘The other constant we have is LED_BUILTIN, which points to the number ° on-board pin, which usually equates to the number 13. In addition to this, we have the C/C++ constants true and false. Arduino Math Constants

You might also like