Friday, August 28, 2020

Reading Digital Inputs From PortB With PortD Outputs Of PIC16F877A With MikroC

Overview Of PIC16F877A Digital Input/Output

PIC16F877A comes with five digital I/O ports names from PortA to PortE. Since the device is 8-bit, the data bus of each port are 8-bit. From PortA to PortD the I/O are fully 8-bit wide, except PortE that uses only 3-bit of the 8-bit Port register.
Beside the digital I/O, there are some analog input output function multiplexed with any Port that we don't mention here. Any relevance's will be talk on next section.

Reading Digital Inputs From PortB With PortD Outputs
PIC16F877A Pins Diagram

PORT Registers 

PORT registers locate in the special function register (SFR). Each port has its corresponding name and address of the SFR.
  • PORTA locates at 0x05
  • PORTB locates at 0x06
  • PORTC locates at 0x07
  • PORTD locates at 0x08
  • PORTE locates at 0x09
Each port are bi-direction read and write. Each PORT direction (input or output) is configured by its corresponding TRIS register.
For example,
  • PORTA=0xFF
  • PORTD=0xAA


TRIS Registers

Tri-state (TRIS) register set the direction for its corresponding PORT register. As mention above, this device contains up to five PORT the TRIS register is also have up to five corresponding registers. TRIS are the member of the SFR. They have their own address in the SFR.
  • TRISA locates at 0x85
  • TRISB locates at 0x86
  • TRISC locates at 0x87
  • TRISD locates at 0x88
  • TRISE locates at 0x89
Assigning '1' to the TRIS, allowing the corresponding PORT as digital input, otherwise configuring it to a digital output.
For example:
  • TRISC=0x0F - The lower nibble of PORTC is digital input while the higher nibble is a digital output.
  • TRISA=0xF0 - The lower nibble of PORTA is digital output while the higher nibble is a digital input.

PORTB and PORTD

PORTB and TRISB

As mention earlier PORTB is a digital bi-directional I/O port. It has a corresponding direction control register TRISB. Setting all bits of TRISB to '1' assigns all bits of PORTB to digital input, otherwise digital output.

Registers relate to PORTB

All digital pins of PORTB have their own weak pull up resistor. By clearing the RBPU (PORTB Pull-up Enable Bit) bit of the OPTION_REG, it will enable the pull up resistors to all pins of PORTB. Hence, PORTB is internally wired to VDD via resistors, making it read HIGH.



PORTD and TRISD

Similarly, PORTD is a digital bi-directional I/O port. The corresponding direction control is TRISD. It also come with Schmitt Trigger input. This port also work as a microprocessor parallel slave port but I don't mention here.

Registers relate to PORTD

MikroC Digital I/O Port Programming

Programming the digital input output port for PIC16F877A could make from scratch. In this start up example, I use the controller to read digital input from PORTB and display them on PORTD.



Reading Digital Inputs From PortB With PortD Outputs
Schematic Diagram

PORTB is internally wired to HIGH. PORTD wire to 8-bit LED output.

MikroC source code:


A simulation screen shot:

Reading Digital Inputs From PortB With PortD Outputs
A Simulation Screen Shot

Click here to download the complete example. I use my own development board to test this program.

Reading Digital Inputs From PortB With PortD Outputs Of PIC16F877A With MikroC
Tested Program

It also has a video of my experiment.


Thursday, August 27, 2020

Blinking The PIC16F877A With MikroC

Overview Of PIC16F877A

PIC16F877A is an old PICMicro device released in 2003. At the period that this device was very popular due to their large amount of I/O pins, a large memory, and a rich of peripherals to fit most of embedded applications. It was listed at the top of its mid-range 8-bit PICMicro.

However, there are many new released mid-range 8-bit devices. They have a lot of new features and more advantage over PIC16F877A. But the PIC16F877A is still in use in academic purposes and still useful in many typical electronic control projects.


Blinking The PIC16F877A With MikroC
A piece of PIC16F877A-I/P I used for prototyping


Blinking The PIC16F877A With MikroC
A screen shot of the running program

C Compilers For PICMicro

Many C compilers designed to target PIC devices. At the time I was at university, the popular C compiler are Hi-tech PICC, CCS PICC, and MikroC. 

MikroC from Mikroelectronika offers a free version of coding below the size of 2 KB, otherwise we will need to buy the compiler's license.


MikroC is not only support for PICMicro, but it's designed to fit many other architecture, ARM, AVR, and legacy 8051.But they are sold separately. The coding of C in this compiler remain almost the same in syntax and function libraries for all targeted architecture.


Simulation And Hardware Prototyping

Proteus is a simulating software based on SPICE. It has a lot of model and libraries for many analog, digital and microprocessor devices including PICMicro. 
Using this software could save a lot of time of doing the prototyping project in real hardware, especially a breadboard prototyping. Additionally, it could cut down the devices burning due to any wrong connection or over voltage during the prototyping.


Getting Start With MikroC Pro For PIC

MikroC Pro for PIC support all 8-bit PIC devices at the specific time of released version. It has a help file that demonstrates how to use C coding and function libraries. 


In this example, I show a simple LED blinking from the 8-bit of PORTD. PORTD of PIC16F877A is a pure digital input outputs port, without any multiplexing with analog peripherals.

MikroC source code lists below.

Circuit diagram made with Proteus.

Blinking The PIC16F877A With MikroC
Circuit Diagram


I have been using PICKit2 for device programming many years now. It still useful for any programming for most of the earlier version of PICMicro.



Blinking The PIC16F877A With MikroC
Using the PICKit2 to program the device

I use my own development board to test this program.

Blinking The PIC16F877A With MikroC
Testing this program on the development board

I make a video demonstrating how to get starting to use the compiler.


Wednesday, August 26, 2020

An Altera MAX CPLD DIY Learning Board

Overview Of Altera MAX CPLD Series

The MAX series CPLD from Altera ( now become a part of Intel ), is a low power and low cost CPLD released since 1993. They shipped with non-volatile memory (especially Flash memory ) for programming.

For educational purpose, there are many development boards released by the device's vendor itself and other third party vendors. However, some MAX CPLD device come with PLCC package allowing the use of additional socket adapter. It enables an easy way for students and hobbyists to make a DIY prototyping.

An Altera MAX DIY CPLD Learning Board
I made a CPLD board using EPM7128SCL84-15 of the flash and JTAG-based  MAX series.

The EPM7128SCL84 is a CPLD in the MAX 7000S series. It bases on Flash technology allowing the user to store program permanently even the system is power off. It contains 2,500 usable gates within its 128 macrocells.

A device comparison table of many part numbers within the flash-based device in the MAX 7000S.

The MAX 7000S families, come with ISP and JTAG interface. Here, I don't mention the MAX 7000 series due to irrelevance.
 
An Altera USB Blaster is a device allowing the programming from a host computer to the target Altera CPLD/FPGA device via its JTAG port interfaces.



An Altera MAX DIY CPLD Learning Board
An Altera USB Blaster I got in 2014 from E Bay.
 

I bought some Altera CPLD chip from E Bay since 2014 with a USB blaster. An Altera chip costed around 5 $ from online market. Altera USB blaster costs about 6 $ from the same market.

Before Starting to program this device, I get used to a Xilinx XC9500 series. I code them using VHDL and a little of Verilog. I was aware of burning the Xilinx chip and its USB JTAG because those Xilinx devices costs far more expensive than the Altera one's.



A Xilinx XC95108 device has a similar capabilities with an Altera EPM7128S one's, but costing nearly 20 $. A Xilinx USB DLC9G USB JTAG costed around 30 $ at that time.

Designing A DIY Experimental Board For MAX 7000S

In 2014, I had enough working skills on CPLD/FPGA. I decided to prototype my own board. It was very hard due to lack of components in the local market.
Referring to EDA tools, KiCAD and Altium have a lot of components library and footprints. However it took a lot of time to design this kind of device in those EDA tools. Due to my long term working in using Proteus, I decided to make my own component symbols, an making a schematic and PCB design in that tool.



It consumed nearly one week of a design job in the computer, PCB fabrication and assembling. But before this finalized stuff, I spent many months working on drafting.

An Altera MAX DIY CPLD Learning Board
Schematic Diagram Of Main Sheet

An Altera MAX DIY CPLD Learning Board
Schematic Diagram Sheet 2

Within this design I putted many peripherals:
  1. A regulated +5 V DC power supply with LED indicator 
  2. A 25.178 MHz oscillator
  3. A JTAG socket
  4. Two push buttons
  5. Four slide switches
  6. Eight output LEDs
  7. A main EPM7128SCL84 CPLD with its pin headers
  8. A legacy PS/2 Interface
  9. A VGA port
  10. A four-digit 0.36 inch common cathode multiplex 7-segment display


An Altera MAX DIY CPLD Learning Board
A 3D Model Of This Design

An Altera MAX DIY CPLD Learning Board
Copper Side

An Altera MAX DIY CPLD Learning Board
Components Side

Click here if you wish to download its completed design.

I made a lot of works on VHDL and  Verilog coding with CPLD/FPGA. From now, I will post all those finished studies.

Wi-Fi Networks Scanning Using ESP8266 With SPI TFT Display

TFT display module is widely available from online stores. The programming interface could make from scratch with Arduino ready to use libraries. It has many examples included.

The esp8266 IoT module is a low cost development platform with Arduino compatible.

In this example I use an esp8266 IoT module to scan all nearby WiFi networks, and display them on a ST7735 1.8" 128x160 SPI LCD module. It is very low cost from online store.

Wi-Fi Networks Scanning Using ESP8266 With SPI TFT Display
A Wi-Fi Scanning Using My Home Router


I use hardware SPI of esp8266. But it will need more control pins such as D/C, CS and Reset pin.

Wi-Fi Networks Scanning Using ESP8266 With SPI TFT Display
A 1.8 inches SPI 128x160 TFT LCD

 

Connect  the TFT LCD the esp8266 to module as below:



  1. GND to GND
  2. VCC and BLK to Vin(+5V)
  3. D/C to D1
  4. CS   to D8
  5. RST to D2
  6. CLK to D5 (HSCLK)
  7. DIN  to D7 (HMOSI)

The programming requires ucblib library for TFT from github. You can install it via Arduino library manager.

Wi-Fi Networks Scanning Using ESP8266 With SPI TFT Display
esp8266 and TFT display connections diagram





Arduino Source Code:


 

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)