Interfacing the 8051 Project Board
with a 12 bit - 4 channel ADC using SPI bus

David Lewis

Demonstration of SPI communication with MCP3204 ADC converter with 8051 project board.

Although the SST89E516RD chip on this board does have SPI capability, the SPI library in Mikro-C for 8051 does not seem to work with the chip, possibly because a substitute chip AT89C51RD2 has to be used by the compiler. To get around this problem, another SPI chip AT89S8253 was substituted for the 89E516RD on board. This chip can be selected in the compiler and works with all the libraries.

The above diagram shows one channel of the MCP3204 connected to a variable resistor. The only connections to the mcu are pins 8,9,10,and 11, which correspond to P3.5(chip select), P1.5(serial data input), P1.6(serial data output) and P1.7(SPI clock) respectively.

A program was written to read the integer output of the ADC and display it on a LCD panel. The reference voltage was set at 5V. Since the ADC is 12 bit, the maximum output would be 111111111111, which is 4095 and this would correspond to 5V. The reading shown on the above equipment photo is 1377 and by simple arithmetic, this would be equal to 1.68V.


* Project name:
ADC_Test (Demonstration of SPI communication with AD converter)
Written by David Lewis
* Description:
This project is a simple demonstration of SPI communication with MCP3204
ADC converter. The integer output from ADC, channel 0, is displayed on a
LCD panel. For 5V input, the displayed value is 4095 since ADC is a 12 bit
* Test configuration:
MCU: AT89S8253
dev.board: Project board for SST89E516RD
Wichit Sirichote,
Oscillator: External Clock 12.0000 MHz
Ext. Modules: Lcd 2x16
Compiler: mikroC PRO for 8051


sbit ADC_CS at P3_5_bit;
unsigned int dataMSB;
unsigned int dataLSB;
int result;
int reading;
char txt;

// Lcd module connections
sbit LCD_RS at P2_6_bit;
sbit LCD_EN at P2_7_bit;
sbit LCD_RW at P2_5_bit; // must be low
sbit LCD_D4 at P0_4_bit;
sbit LCD_D5 at P0_5_bit;
sbit LCD_D6 at P0_6_bit;
sbit LCD_D7 at P0_7_bit;
// End Lcd module connections

void Init(){

SPI1_Init(); //init SPI
ADC_CS=1; //deselect MCP3204
P0= 0;
LCD_RW =0;
Lcd_Init(); //init LCD

unsigned int getADC(unsigned short channel){

ADC_CS=0; //select MCP3204
dataMSB=SPI1_Read(channel)& 0x0F;
result=dataMSB | dataLSB;
ADC_CS=1; //deselect MCP3204
return result;


void main(){

reading=getADC(0); //get ADC result from Channel 0
IntToStr(reading, txt); //convert integer to string
Lcd_Out(1,5,txt); //put number on display


Source code Listing

Technical information Links:

8051 Project board

MCU: AT89S8253 Datasheet
Compiler: mikroC PRO for 8051

Download source code in zip file


2 June 2020