Monday 16 April 2012

LCD Interface with 8051 Microntroller


C Code


#include <regx51.h>
#define LCD_COMMAND 0
#define LCD_DATA 1
#define LCD_RS P0_0       //Edit it per your circuit design
#define LCD_RW P0_1       //Edit it per your circuit design
#define LCD_EN P0_2       //Edit it per your circuit design
#define LCD_PORT P2       //Edit it per your circuit design

char *message_1 = "electronicsprojs";
char *message_2 = ".blogspot.com";

/*Function Prototypes*/

void LCD_delay(unsigned int);
void LCD_putc(int,int);
void LCD_puts(unsigned char*);
void LCD_init();

main()
{
 LCD_init();
 LCD_putc(0x80,LCD_COMMAND); //Write to Row 1
 LCD_puts(message_1);
 LCD_putc(0xC0,LCD_COMMAND); //Write to Row 2
 LCD_puts(message_2);
 LCD_delay(1000);
 while(1);
}

void LCD_init()
{
 LCD_EN = 1;
 LCD_RS = 0;

 LCD_putc(0x38,LCD_COMMAND); //Use 2 lines 5X7 matrix
 LCD_putc(0x0C,LCD_COMMAND); //Display on Cursor on
 LCD_putc(0x01,LCD_COMMAND); //Clear Screen
 LCD_delay(256);
}

void LCD_delay(unsigned int i)
{
 while(i>0)
  i--;
}


void LCD_putc(int character, int type)
{

 LCD_delay(10);
 LCD_RS = type;  //1 : Write Data, 0 : Write Command
 LCD_RW = 0;
 LCD_PORT = character;
 LCD_EN = 0;   //Latch data with a low to high pulse
 LCD_delay(10);
 LCD_EN = 1;
}

void LCD_puts(unsigned char *string)
{

 while (*string)
 {
  LCD_putc(*string++,LCD_DATA);
 }
}


Sunday 1 April 2012

Infrared Beam Break Detector

This purpose of this article is to design a circuit using Infrared signals to detect a beam break which can be used in multiple real world applications. The IR receiver used is TSOP1738. Below are some of the main requirements of Infrared Transmiter signal properties as described in the datasheet
  • Carrier frequency should be close to the  center frequency of the bandpass (38kHz)
  • Burst length should be 10 cycles/burst or longer
  • After each burst which is between 10 cycles and 70 cycles a gap time of at least 14 cycles is neccessary

Design


1. Carrier Frequency (f1) : The center frequency of TSOP1738 is 38kHz

f1 = 1.44/((Ra1+2Rb1)C)
f1 = 38kHz

Let
Ra1 = 1k
C = 0.01uF

With that Rb1 = 1.394k or
Rb1= 2k variable resistor


2. Burst and Gap frequency (f2) : Let burst cycle equals gap cycle be equal to 40 cycles (burst between 10 and 70 cycles and gap greater than14 cycles)

f2 = 38k/ 40
f2 = 950
f2 = 1.44/((Ra2+2Rb2)C)

Let
Ra2 = 10k
C = 0.01uF

With that
Rb2 = 70.789k or
Rb2 = 100k variable resistor

Note:
1. BC547 is used at the output of transmitter as switching transmitter to boost the voltage increasing the range.

2. When the Infrared beam is broken, the output of TSOP1738 goes high. Using switching transistor 2N2222, the signal is inverted to High to Low which can be directly interfaced to External edge triggered interrupts of 8051 (EXT0 and EXT1)

Infrared beam break detector transmitter receiver circuit