Total Pageviews

Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, January 28, 2014

8 bit lcd library function for hitech-c

8 bit lcd library function for hitech-c



#ifndef D0
#define D0 RB0
#define D1 RB1
#define D2 RB2
#define D3 RB3
#endif



void Lcd8_Port(char a)
{
if(a & 1)
D0 = 1;
else
D0 = 0;

if(a & 2)
D1 = 1;
else
D1 = 0;

if(a & 4)
D2 = 1;
else
D2 = 0;

if(a & 8)
D3 = 1;
else
D3 = 0;

if(a & 16)
D4 = 1;
else
D4 = 0;

if(a & 32)
D5 = 1;
else
D5 = 0;

if(a & 64)
D6 = 1;
else
D6 = 0;

if(a & 128)
D7 = 1;
else
D7 = 0;
}
void Lcd8_Cmd(char a)
{
  RS = 0;
  RW=  0;         // => RS = 0
  Lcd8_Port(a);             //Data transfer
  EN  = 1;             // => E = 1
  __delay_ms(5);
  EN  = 0;             // => E = 0
}

Lcd8_Clear()
{
 Lcd8_Cmd(1);
}

void Lcd8_Set_Cursor(char a, char b)
{
if(a == 1)
 Lcd8_Cmd(0x80 + b);
else if(a == 2)
Lcd8_Cmd(0xC0 + b);
}

void Lcd8_Init()
{
Lcd8_Port(0x00);
RS = 0;
RW=0;
__delay_ms(25);

  Lcd8_Cmd(0x30);
__delay_ms(5);
  Lcd8_Cmd(0x30);
__delay_ms(15);
  Lcd8_Cmd(0x30);

  Lcd8_Cmd(0x38);    //function set
  Lcd8_Cmd(0x0C);    //display on,cursor off,blink off
  Lcd8_Cmd(0x01);    //clear display
  Lcd8_Cmd(0x06);    //entry mode, set increment
}

void Lcd8_Write_Char(char a)
{
   RS = 1;             // => RS = 1
RW=0;
   Lcd8_Port(a);             //Data transfer
   EN  = 1;             // => E = 1
  __delay_ms(4);
   EN  = 0;             // => E = 04
}

void Lcd8_Write_String(char *a)
{
int i;
for(i=0;a[i]!='\0';i++)
Lcd8_Write_Char(a[i]);
}

void Lcd8_Shift_Right()
{
Lcd8_Cmd(0x1C);
}

void Lcd8_Shift_Left()
{
Lcd8_Cmd(0x18);
}

EXTERNALINTERRUPT(PIC16F877A)-programming





PROGRAM

#include<pic.h>
#include<htc.h>

#define RS RC0
#define RW RC1
#define EN RC2
#define D0 RD0
#define D1 RD1
#define D2 RD2
#define D3 RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7 

#define _XTAL_FREQ 4000000
__CONFIG(WDTDIS & XT & UNPROTECT);
#include"lcd.h"
char a[10];
int count=0,i;
void interrupt isr()
{
if(INTF==1)
{
count++;
i=count;
a[1]=i%10+0x30;
i=i/10;
a[2]=i%10+0x30;
if(count<10)
{
Lcd8_Clear();
Lcd8_Set_Cursor(1,0);
Lcd8_Write_Char(a[1]);
}

if(count>9)
{
Lcd8_Clear();
Lcd8_Set_Cursor(1,0);
Lcd8_Write_Char(a[2]);
Lcd8_Set_Cursor(1,1);
Lcd8_Write_Char(a[1]);
}
INTF=0;
}
}



void main()
{

TXSTA=0X24;
RCSTA=0X90;
SPBRG=0X19;
TRISC=0x80;
TRISD=0x00;
TRISB=0x01;
TXIF=0;
RCIF=0;
GIE=1;
PEIE=1;
RCIE=1;
INTE=1;
INTEDG=1;
INTF=0;
Lcd8_Init();
Lcd8_Clear();
Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("interrupt");
while(1);
}

Friday, January 24, 2014

SAMPLE TRANSMISSION PROGRAM FOR PIC16F877A

SAMPLE TRANSMISSION PROGRAM FOR PIC16F877A



# include<pic.h>

#define _XTAL_FREQ 4000000

__CONFIG(WDTDIS & XT & UNPROTECT);

void main()
{
TXSTA=0X24;
RCSTA=0X90;
SPBRG=0X19;
TRISC=0X80;
while(1)
{
TXREG='k';
while(TXIF==0);
TXIF=0;
}
}

This is a sample program for transmitting character 'k' continuously.