Tuesday, December 22, 2020

Interfacing PIC18F4550 to 74HC595 CCS PICC

A shift register chip is very useful for expanding the digital I/O. Getting more digital outputs, the 74HC595 is very popular due to its ease of use. It is called a serial in parallel out shift register IC. The 74XX prefix belong to the clue logic family of the digital IC.

74HC595 chips in DIP package

The communication interface between the MCU and this controller is quite simple. It basically use three pins as in the form of the Serial Peripheral Interface (SPI) which are,

  • Serial Data
  • Serial Clock
  • Enable

This IC has an 8 bit output with an optional serial data out for a daisy-chain connection.

Pin diagram of this device

An SPI communication that used by the MCU to send the data to this chip could be an SPI peripheral inside the MCU, or a software bit-banging written by the programmer. The SPI peripheral usually has a fixed pins but using the software bit-banging the output pins are select-able by the programmer.

With the software bit-banging, the program need to spend more more time executing this SPI-like communication. In this case it doesn't provide a high speed SPI.

CCS PICC has a built-in driver allowing the PIC microcontroller to send a serial data to this chip. We need to set up some basic steps as shown below:

  1. Select a serial data pin
  2. Select a serial clock pin
  3. Select a enable pin
  4. Set the numbers of register
  5. Send some bytes of data with a preset numbers of register

The 74595.c is ready to use in the CCS PICC compiler after the installation. The write_expanded_outputs(eo) function writes some bytes to this chip. The number of bytes is a preset number of register.

In this example, PIC18F4550 connects to a two-digit display driven by two distinct shift registers. The MCU counts the number of input up to 99 before it reset to 0.

PIC18F4550 Interfaces To 74HC595 Shift Registers
Schematic Diagram

Source of this program is written using CCS PICC.

#include<18f4550.h>

/*Use high speed clock no PLL prescaler 
no system clock post scaler */
#fuses HS,PLL1,CPUDIV1,NOWDT
#use delay(clock=20M)

#define EXP_OUT_ENABLE  PIN_D0
#define EXP_OUT_CLOCK   PIN_D1
#define EXP_OUT_DO      PIN_D2
#define NUMBER_OF_74595 2

#include<74595.c>

 
 
void main(void){
unsigned char patterns[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,
 0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
   unsigned char cnt=0;
   unsigned char digits[2];
   //Clear PORTD
   output_D(0x00);
   //Set PORTD To Output
   set_tris_D(0x00);
   
      
   while(1){
      digits[0]=patterns[cnt/10];
      digits[1]=patterns[cnt%10];
      write_expanded_outputs(&digits);
      delay_ms(1000);
      cnt++;
      if(cnt>=100) cnt=0;
   }
}


No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)