Pages

Wednesday, 23 January 2013

C# Code as drivers for interfacing LCD display with 8051

// Author :- ** Mufaddal Kagda **

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace WindowsFormsApplication1
{
         public partial class Form1 : Form
        {
              public Form1()
             {
                   InitializeComponent();
             }

     
             SerialPort SP = new SerialPort("COM35");
     

             private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                 SP.BaudRate = 9600;
                 SP.Parity = Parity.None;
                 SP.DataBits = 8;
                 SP.StopBits = StopBits.One;
                 SP.RtsEnable = true;
                 SP.DtrEnable = true;
                 SP.Encoding.GetEncoder();
                 SP.ReceivedBytesThreshold = 1;
                 SP.NewLine = Environment.NewLine;
         
                 try
                {
                     SP.Open();
                     SP.Write((e.KeyChar).ToString());
                     Thread.Sleep(10);
                     SP.Close();
                }
                catch (Exception ex)
               {
                    MessageBox.Show(ex.Message);
               }
         
         }
     }
}

Sunday, 20 January 2013

8051 Program to take input from COM port and Display on LCD


// Author :- ** Mufaddal Kagda **
//Embeded C program ( keil Program)
// 8051 Microcontroller

/*This Program is made to display Characters on LCD screen  typed From PC Keyboard --interfaced with 8051 */

#include <reg51.h>
#include <string.h>

sbit rw=P2^0;  //read write pin
sbit rs=P2^1;  // data/command pin
sbit en=P2^2;   // declare p2.2 as read/write pin
sbit b = P1^7;   // busy flag
unsigned char card[12];

void writecmd(unsigned char a); // function to send command to LCD
void writedat(unsigned char b);  // function to send data to LCD
void busy();   // function to check LCD is busy or not
void writestr(unsigned char *s); // function to write string on LCD

void writecmd(unsigned char a)
{
 busy();   // check for LCD is busy or not
 rs = 0;   // clear rs pin for command
 rw = 0;   // clear rw pin to write
 P1 = a;   // send command character
 en = 1;   // strob LCD
 en = 0;
}
void writedat(unsigned char b)
{
 busy();   // check for LCD is busy or not
 rs = 1;   // set rs pin for data
 rw = 0;   // clear rw pin to write
 P1 = b;   // send data character
 en = 1;   // strob LCD
 en = 0;
}
void busy()
{
         en = 0;   // disable display
         P1 = 0xFF;  // configur P0 as input
         rs = 0;   // clear rs pin for command
         rw = 1;   // set rw pin to read
         while(b==1)
        {
               en=0;   // strob LCD till P1.7 is 1
               en=1;
        }
        en=0;
}
void writestr(unsigned char *s)
{
      unsigned char l,i;
      l = strlen(s);               // get the length of string
      for(i=1;i<=l;i++)
      {
           writedat(*s);              // write every char one by one
           s++;
      }
}
 
main()
{

    P0=0x00;                      // P0 and P2 as output ports
    P2=0x00;
    TMOD=0x20;            //Enable Timer 1
    TH1=0XFD;
    SCON=0x50;
    TR1=1;
 
    writecmd(0x3C);               // initialize LCD
    writecmd(0x0E);  
    writecmd(0x01);              // clear memory and home cursor

while(1)
{
while(RI==0);
card[0]=SBUF;
RI=0;
writestr(card);
  }
   }