PIC12F675 UART Data Send to Tera Term Emulator
by coalpeck in Circuits > Microcontrollers
877 Views, 0 Favorites, 0 Comments
PIC12F675 UART Data Send to Tera Term Emulator
This presentation will detail how data bytes are sent from the PIC12F675 micro-controller code to appear on a PC emulator. Simplifying the process is the reason this presentation was created. This presentation is very basic but effective by utilizing the UART data transfer protocol and a PC running "Tera Term" emulator software.
Arduino is the preferred micro-controller when prototyping Only Keypads encoder designs and when an encoder design is proven the next step is to replace the Arduino with an onboard micro-controller. Reason being, the overhead of the Arduino is no longer required and the PCB footprint is best minimized. To remain cost effective a low- end PIC micro-controller is preferred but the lower-end PIC does not support the TX and RX serial port protocol.
The lack of a physical serial port and serial monitor capability on the low-end PIC presents a problem when the encoder code is transferred from the Arduino to the PIC and an emulator is required to test the characters sent from the Keypad to the PIC. To solve this issue a simple TX data protocol is coded on the PIC to send the Keypad character to the "Tera Term " emulator software.
Objective of this presentation:
The objective of this presentation is for the hobbyist to use a simplified UART code for PIC micro-controllers that lack integrated UART capability that more advanced micro-controllers handle behind the scenes.
Comment:
As with any new project design cost is always a concern but the small investment for a PicKit programmer will open new avenues for personal projects when a manufactured PCB is incorporated into a final integrated build. The PIC micro-controller used in this project is coded in C for the most part and the hobbyist will come to realize the similarity with the Arduino code. The time spent on this presentation will be valued when developing future project ideas.
Supplies
1- Breadboard of choice and patch wires or DuPont wires
2- PIC12F675 micro-controller (Can be purchased on Ebay or online stores)
3- PICKit3 Programmer (Can be purchased on Ebay or online stores)
4- FT232RL Serial Adapter (Can be purchased on Ebay or online stores)
5- 5VDC power supply (USB wall adapter works)
6- MPLAB X IDE (download from Microchip) https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide
There is also a download for the MPLABX IPE compiler. It is not used in this presentation but noted.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
The programmer built into the MPLABX IDE can be used for upload to the PIC.
The PICKitEasy programmer software in step 9 is an alternative to the MPLABX IDE programmer.
The PICKitEasy programmer software handles PICKit2 and PICKit3 legacy programmers.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
7- Tera Term (download) (Google "Tera Term" for free download)
Not shown in pictures but required:
8- USB cables for Pickit3 and FT232RL
9- Two 1K 1/4 watt resistors
10- One 180 ohm 1/4 watt resistor
11- One Green or Red pin led
Project Index
STEP by STEP
2- Build the Breadboard
3- Download the software tools
4- Basic UART protocol
5- Create the MPLAB project
6- Copy and Paste the PIC12F675 UART code into MPLAB X project
7- Analyze the code
8- Demonstrate the PIC communicating with the Tera Term emulator
9- Additional Information
Build the Breadboard
The attached schematic illustrates the breadboard circuit.
The build is a self explanatory assembly detailing point to point connections of components.
A few pointers:
1- Note the arrow on the PicKit3 identifying pin #1
2- Check FT232RL for proper 5vdc bird jumper selection < NOT 3.3vdc >
For a download and printable version of the schematic click on or paste the following share link into your URL
Chromebook users: highlight the URL below, alt with click, click Open
https://drive.google.com/file/d/1-Qt7pKk5_CKfNOWjpC847tuqBIba8yFH/view?usp=sharing
Download the Software Tools
The goal of this presentation is to demonstrate UART data transfer utilizing custom C code for the PIC12F675 micro-controller. To avoid over information and going off script the software downloads are best left to alternative means.
In today's world YouTube is a wonderful resource for information and there are numerous videos explaining the software downloads for the required tools. It would be fruitless in this presentation to reproduce what is already professionally accomplished by others. There may be hobbyists who already have the required tools but for those not acquainted Youtube videos will be the best resource.
The following Youtube video explains the MPLABX IDE download process. There are many others available.
https://www.youtube.com/watch?v=cB0rCsfGUOQ
Below are URL links to get started on downloading the MPLABX software.
The Microchip web-page may change and require additional searching for proper links.
The two websites are basically identical.
MPLAB X IDE (download from Microchip) https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide
MPLABX download: MPLABX IDE: https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide
Below is the link to download the Tera Term emulator software.
Tera Term download: https://tera-term.en.lo4d.com/windows
Basic UART Protocol
UART (Universal Asynchronous Receiver/Transmitter) is a means to transfer data using serial communication over two wires, identified as RX and TX data wires. In this presentation the TX (Transmit) line will be used to send data from the PIC micro-controller to a PC running the Tera-Term emulator program software.
UART is the most basic communication protocol consisting of a start bit, eight data bits, and stop bit to initiate a simple data transfer in this presentation. There are other bits such as parity but not necessary to initiate a data transfer and not used in this presentation. The TX line is controlled by the PIC micro-controller and initiates the data transfer.
For this presentation the data transfer is calculated at 2400 baud (bps.) 1/2400 = .000417 seconds or .417 mili-seconds or 417 micro-seconds per bit. This number will be offset in the PIC code to compensate for PIC internal execution times but the Tera -Term emulator will be set for 2400 baud and no parity. Studying the attached timing trace notice the receiver clock pulse occurs in the middle of the TX data bit sent. This sample technique ensures that the data bit sampled is accurate by sampling at an average data bit pulse length. Based on this method of sampling the clock sequencing between the PIC and the emulator can be within a 10% error.
For a download and printable version of the drawing click on or paste the following share link in your URL
Chromebook users: highlight the URL below, alt with click, click Open
https://drive.google.com/file/d/11S5g2zfrciw75Vt8WFiHckxP1ViJEVep/view?usp=sharing
Research: After reviewing the circuit schematic it can be seen there are pull-down resistors on the TX and RX data lines. Through research, there are varying opinions on using resistors or no resistors. The UART data lines are believed to clock at such a slow rate and the transmitter and receiver are always driving the data lines high or low that no resistors are required.
Others recommend pull-up resistors on RX TX lines to default the UART start bit high during the micro-controller reset cycle. The start bit must transition the TX line from a logic high to logic low to signal the start of a data transfer with the receiver. This is noted as a valid reason for pull-up resistors to default the start bit high to avoid false data transfers.
pull-down resistor:
The pull-down resistors were chosen for this build to suppress line noise from corrupting the data signals and school of thought is transient suppression is best directed to ground.
Not all communications are equal:
There are other protocols that require pull-up resistors to function properly. One such protocol is I2C where pull-up resistors and mandatory for compensating line capacitance depending on the number of devices on the bus, also, maintains line default state and prevents the line from floating. The I2C protocol is for another presentation but keep in mind that various communication protocols require unique designs.
Comment: On pull-up or pull-down resistors
Opinions vary, but when designing hobby projects the circuit architecture can vary when the prototype is not meant for commercial or consumer products where strict product guidelines and testing are mandatory. In the hobby environment, experimenting outside the norm expands the learning process to develop the best methods and solutions.
Create MPLAB X IDE Project
The next step is to build the MPLAB X IDE project to insert the UART code for the PIC12F675 micro-controller.
Launch MPLAB X IDE software
Use the supplied pictures as a guide to build the Project Folder
PIC #1 Create a new project ( Click on folder)
PIC #2 Highlight "Microchip Embedded" and "Standalone Project" (Click Next>)
PIC #3 Select Device "PIC12F675" (Click Next>)
PIC #4 Select Header [Leave at "NONE"] (Click Next>)
PIC #5 Select Compiler [Highlight XC8] (Click Next>)
PIC #6 Select Project Name and Folder: Type in: "Show_Project" or your own Project Name
Browse for your Project Folder or other folder you created to place the Project: (Click Finish)
NOTE: MPLABX will place the Project in its directory if a different folder is not created and selected
PIC #7 In MPLABX select [Projects] in the left bar if not already open and then expand "Show_Project"
Highlight: (Left Click) "Source Files"
PIC #8 Right Click "Source Files" and hover to "NEW" and then Left Click "C.Main File..."
PIC #9 [Name and Location] Type-in under [File Name:] "Show_Project" or your own Project Name
PIC #10 The "Show_Project.c" folder will open in the main window where to place the code
For additional help:
Step #8 contains a video link with a section of the video showing how to create the project
Proceed to the next step to insert the code for PIC12F675 UART
Copy and Paste the PIC12F675 UART Code Into MPLAB X Project
This step supplies the PIC12F675 UART code in a Text file that is used to copy and paste into the MPLAB X project folder "Show_Project". Refer to: 12F675_UART_F_code.txt below
There is a supplied video demonstrating the copy and paste. Refer to: Insert 12F675 Code.mp4 below
Step #8 contains a video link with a section of the video showing the code copy and paste
The following is also a Google Share link for the Text code:
Copy and Paste into your URL or click to view.
Chromebook users: highlight the URL below, alt with click, click Open
https://drive.google.com/file/d/151zXvYK-uaDeG9YDogwrYZla05h0_oKK/view?usp=sharing
Analyze the Code
This step displays the code in five segments referenced by the pictures shown. There is a short video describing each segment of code execution.
Picture #
1- This segment explains lines 1 thru 29. View Segment 1 Code video:
2- This segment explains lines 30 thru 39. View Segment 2 Code video:
Refer to the picture "PIC12F675 General Purpose I/O Byte"
TRISIO = 0X18 command 00011000 reading from the right most bit GP0 to GP5. GP0 and GP1 not used, GP2 output is the TX data line, GP3 input is not used but is the MCLR and must be an input for the PICKit3 to program the PIC12F675, It can then be used for an external input in the code, GP4 input is the RX data line which is not used in this project, GP5 output is for the LED. GP6&7 is not used on the PIC12F675.
3- This segment explains lines 40 thru 78. View Segment 3 Code video:
Refer to the picture "Basic Example of UART Protocol" and "UART Protocol Data Transfer Basic Diagram"
Example data byte 01010101
The data byte sent from the PIC12F675 consists of eight data bits labeled 7 to 0. The eight bits are indexed from the right most bit referred to as bit 0 to the left most bit referred to as bit 7.
The indexing of the eight data bits labeled 7 - 0 from right (0) to left (7) conforms to UART protocol. In UART data transfer the least significant bit (the rightmost bit in the Example data byte (1)) is sent first. Then the remaining bits are sent with the most significant bit (the leftmost bit in the Example data byte (0)) sent last. The transfer order is (0-1-2-3-4-5-6-7)
Referenced in the code the shift left << command followed by the bit index 0 - 7 is as follows.
( <<0 no shift, read bit zero (The least significant bit) which is data bit 1 in the Example data byte 01010101
( <<1 shifts one bit to the left of the least significant bit which is data bit 0 in the Example data byte 01010101
( <<2 shifts two bits to the left of the least significant bit which is data bit 1 in the Example data byte 01010101
( <<3 shifts three bits to the left of the least significant bit which is data bit 0 in the Example data byte 01010101
( <<4 shifts four bits to the left of the least significant bit which is data bit 1 in the Example data byte 01010101
( <<5 shifts five bits to the left of the least significant bit which is data bit 0 in the Example data byte 01010101
( <<6 shifts six bits to the left of the least significant bit which is data bit 1 in the Example data byte 01010101
( <<7 shifts seven bits to the left of the least significant bit which is data bit 0 in the Example data byte 01010101
4- This segment explains lines 79 thru 110. View Segment 4 Code video:
5- This segment explains lines 111 thru 140. View Segment 5 Code video:
The data transfer is set for 2400 bps baud rate which equates to 1/2400 = .000416 seconds or .416 mili-seconds. In the program the data transfer delay is set for .516 mili-seconds which works as an offset in the code execution time. Because this is a programmed time delay and not a crystal frequency divider routine the delay timing is within an error factor but works in this program. Based on researched articles, the transmitter data bit retention time and receiver clock pulse can be within a 10% error on a data transfer. Viewing the picture above it shows the receiver clock pulse reading the data bit somewhere around the mid point of the data bit retention time in order to verify a valid read. Not too close to the rising or falling edges of the data bit.
Downloads
Demonstrate the PIC Communicating With the Tera Term Emulator
View the full video on Youtube for this project UART "TX" Emulator Using PIC12F675 Micro-controller
View the video demonstrating the UART "PIC Data Transfer.mp4" to the TERA TERM emulator software.
Additional Information
The PICKitEasy is a valuable tool as an alternative to the MPLAB x8 compiler. The PICKitEasy is built for legacy PICKit2 and PICKit3 micro-controller hex file uploads.
View the full Youtube video demonstrating the PICKitEasy software and where to purchase.
View video "PICKitEasy Bullet Point.mp4" for uploading the MPLAB X Hex file to the PIC micro-controller.
Thanks for Viewing
Thanks for viewing this presentation of a simplified UART protocol for the hobbyist to explore and integrate into custom projects for personal use.
The Instructables platform is greatly appreciated for posting this presentation.