Introduction
The dsPIC30F2010 is a 16-bit micro-controller. It means that its internal data bus is 16-bit wide. Additionally its I/O data is also 16-bit wide. However a small foot-print 16-bit MCU like the dsPIC30F2010 has only 28 pins including supply voltage pins, ADC voltage pins, clock pins ,etc. So we can get a full 16-bit input output from its pins.
![]() |
| Pin Diagrams |
To get a full 8-bit or 16-bit external I/O, we need to add any I/O expansion chips. These chips implement the SPI or I2C interface. Here I use the PCF8574 I2C I/O expansion chip. This chip an 8-bit bidirectional micro-processor expansion chip.
The PCF8574 Series
The device features an 8-bit quasi-bidirectional I/O port (P0–P7), including latched outputs with high current drive capability for directly driving LEDs. Each quasi-bidirectional I/O can be used as an input or output without the use of a data-direction control signal. At power on, the I/Os are high. In this mode, only a current source to VCC is active.
This chip is suitable for,
- Telecom Shelters: Filter Units
- Servers
- Routers (Telecom Switching Equipment)
- Personal Computers
- Personal Electronics
- Industrial Automation
- Products with GPIO-Limited Processors
![]() |
| PCF8574 Interfacing Diagram |
![]() |
| PCF8574AP DIP-16 |
We can event use this chip for a 4x4 matrix keypad, or driving an HD44780-base character LCD.
![]() |
| Pin Configuration and Functions |
This device has various package types. A PDIP-16 or a SOIC-16 are common for most of electronics hobbyists.
![]() |
| Simplified Block Diagram of Device |
This device has an 8-bit customizable slave address with R/W bit.
We can custom its optional slave address via A2...A0 bits. Its default write address when A2...A0 are wired to GND is 0x40.
![]() |
| Address Reference |
The Master I2C device need to write device slave address followed by output port data twice.
![]() |
| PCF8574 Write Mode |
To read from this I2C slave device, the microprocessor need to write device read address (eg. 0x41), followed by I2C in read mode.
![]() |
| PCF8574 Read Mode |
We can use various I/O devices with this chip.
dsPIC30F2010 I2C Programming using MikroC
MikroC for dsPIC offer a build-in dedicated and software I2C libraries. Both of them are stable and reliable for most of applications. It excepts that the software I2C operates at lower clock frequency.
Here I use its dedicated I2C module. Most of dsPIC30F MCUs have more than one I2C module.
Important :
- I²C library routines require you to specify the module you want to use. To select the desired I²C module, simply change the letter x in the routine prototype for a number from 1 to 3.
- Number of I²C modules per MCU differs from chip to chip. Please, read the appropriate datasheet before utilizing this library.
These are its library routines:
Library Routines
Generic Routines
For more information about using the I2C module, please see this page.
PCF8574AP Output LEDs Example
For an introductory example, the dsPIC30F2010 send an 8-bit data to this chip. The 8-bit output of PCF8574AP connect individual LED.
Schematic:
![]() |
| Schematic |
MikroC Source Code:
- const char PCF8574_W=0x40;
- const char PCF8574_R=0x41;
- const char PCF8574A_W=0x70;
- const char PCF8574A_R=0x71;
- void pcf8574_write(char device, char _data){
- I2C1_Start(); // issue I2C start signal
- I2C1_Write(device); // send byte via I2C (device address + W)
- I2C1_Write(_data); // send byte (data address)
- I2C1_Stop(); // issue I2C stop signal
- }
- void blink(unsigned int duration, unsigned int counts){
- while(counts>0){
- pcf8574_write(PCF8574A_W,0x00);
- Vdelay_ms(duration);
- pcf8574_write(PCF8574A_W,0xFF);
- Vdelay_ms(duration);
- counts--;
- }
- pcf8574_write(PCF8574A_W,0x00);
- }
- void main(){
- char temp = 0, i = 0;
- I2C1_Init(100000); // initialize I2C communication
- Delay_ms(10);
- pcf8574_write(PCF8574A_W,0x00);
- blink(100,100);
- while(1){
- pcf8574_write(PCF8574A_W,temp);
- temp+=(1<<i);
- i++;
- if(i > 8) i = temp = 0;
- Delay_ms(200);
- }
- }
I tested this code on my DIY dsPIC30F2010 Prototype Board.
![]() |
| I tested this code on my DIY dsPIC30F2010 Prototype Board. |
![]() |
| I tested this code on my DIY dsPIC30F2010 Prototype Board. |
![]() |
| I tested this code on my DIY dsPIC30F2010 Prototype Board. |
![]() |
| I tested this code on my DIY dsPIC30F2010 Prototype Board. |
For a full I2C devices interfacing example using the ATMega644P chip see this post.


.jpg)












No comments:
Post a Comment