Google

Feb 28, 2010

Program to initialise the LCD in 4 bit mode using PIC microcontroller

It was for 16F72 at 4Mhz written in cc5x. LCD is connected to PORTB.RS at RB7,RW at RB1,EN at RB6. DB7 at RB2,DB6 at RB3, DB5 at RB4, and DB4 at RB5. A function delay_ms() is used , which is not shown here.

code will work for 2x16 character LCD modules.

void lcdw(unsigned char m)
{
PORTB.2=m.7;
PORTB.3=m.6;
PORTB.4=m.5;
PORTB.5=m.4;
en=1;
nop();
nop();
en=0;
}

void nbw(unsigned char m)
{
PORTB.2=m.7;
PORTB.3=m.6;
PORTB.4=m.5;
PORTB.5=m.4;
en=1;
nop();
nop();
en=0;
PORTB.2=m.3;
PORTB.3=m.2;
PORTB.4=m.1;
PORTB.5=m.0;
en=1;
nop();
nop();
en=0;
}

void goadr(unsigned char a)
{

rs=0;
nbw(0x80 + a);
delay_ms(5); // delay of 5msec

}


void main()
{
................

TRISB=0;
PORTB=0;
rw=0;
rs=0;
lcdw(0x28); // lcdw function is only used once to initialise the LCD to 4 bit mode.
delay_ms(5);
nbw(0x28);
delay_ms(5);
nbw(0x0c);
delay_ms(5);
nbw(0x06);
delay_ms(5);
nbw(0x01);
delay_ms(5);
goadr(0x02);
rs=1;
nbw('a'); //displays the character "a" at location 0x02
nbw('b'); //displays the character "b" at location 0x03
.........................


}

Feb 25, 2010

Program for multiplexing of led displays for pic microcontrollers

Suppose you want to design the ac digital voltmeter rang up to 0-300v or above, by using any pic 8-bit mcu, and want to use 3, 7-segment display for it then there can be a problem as to how do you indicate such large value on display

then you can go with the following approch

use BCD to 7 segment converter, so that only 4 bits can be used to control a single 7 seven segment display..... so in total u need 12 output lines. you can get 12 output bits by using 2 different ports of any suitable 8 bit microcontroller. link to one such converter http://www.ee.washington.edu/stores/DataSheets/74ls/74ls47.pdf

use 7 bits from one port for all 3 displays and use 3 other bits to select led's this is done very fast so human eye can not make out that the displays are glowing sequencially and not continously.
here is sample code for pic

#include
#include

void DisplayNumber( unsigned int number );

void main()
{
trisb = 0;
trisa = 0xFF;

unsigned int randNumb = 0;

while( 1 )
{

while( porta.0 == 0 ) // wait for key pressed
DisplayNumber( randNumb ); // display number to keep display refreshed

// while key pressed increment counter
// Number will be random based on how long input is turned on
while( porta.0 == 1 )
{
randNumb++;
if( ++randNumb > 9999 )
randNumb = 0;
}

// display a series of random numbers so it looks like we are
char j;
for( j = 0; j < x =" rand();" i =" 0;" i =" 0x01;" i =" 0b1000;">>= 1 )
{
digit = number % 10;
number /= 10;

portb = digit & 0x0F;
portb = (digit & 0x0F) | (i <<>

Feb 20, 2010

version control system for keil & MPLAB.

Hi when you are working on large project which involve large number of programs and many developers work at same thing then thing will become hard to manage and the project may Fail.

so when you are dealing with Such kind of progects while developing Microprocessor microcontroller Projects it is all ways better to use CVS Code version system or Version control sytems.It is the best way to share code, you could do the same in MATLAB, Keil or MPlab but it is much efficient to use SVN.



Please find the bellow video to learn CVS/SVN

Tutorial: using tortoisesvn, subversion on windows from Mark Guzman on Vimeo.

Feb 17, 2010

LED blinking program for Pic microcontroller

Here is the program for Pic microcontroller PIC16F877A
to blink a LED connected to B3 of PORTC,

This program works for Mplab. or using HiTECH PRO Lite compiler.


PICClite code may be

#include
#include "delay.h"
#define _XTAL_FREQ 4000000
_CONFIG(MCLREN & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);

void main()

{
TRISC=0;
while (1)
{
PORTC = 8;
DelayMs(250);DelayMs(250);
PORTC = 0;
DelayMs(250);DelayMs(250);
}

}

in PIC_Clite , "delay.h" has to be included because its MACRO, but in PRO its inbuilt

#include
#define _XTAL_FREQ 4000000
_CONFIG(MCLREN & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);

void main()

{
TRISC=0;
while (1)
{
PORTC = 8;
__delay_ms(100);_delay_ms(100); // use this delay to test the code
__delay_ms(100);_delay_ms(100);
PORTC = 0;
__delay_ms(100);_delay_ms(100);
__delay_ms(100);_delay_ms(100);
}

}
i didnt use _delay(100000); because whn Xtal Freq is high(20Mz) the delay changes & you will not be able to see the LEDs blinking. ensure that watchdog timer is disabled in _CONFIG, hope it works..

Feb 13, 2010

A microprocessor Program to convert BCD pack and Unpack number for 8085.

Please find the Below program to Pack the two unpacked BCD numbers stored in memory locations 4200H and 4201H and store result in memory location 4300H. Assume the least significant digit is stored at 4200H.


Here is the Sample problem:
(4200H) = 04
(4201H) = 09
Result = (4300H) = 94


Source program for the above logic

LDA 4201H : Get the Most significant BCD digit
RLC
RLC
RLC
RLC : Adjust the position of the second digit (09 is changed to 90)
ANI FOH : Make least significant BCD digit zero
MOV C, A : store the partial result
LDA 4200H : Get the lower BCD digit
ADD C : Add lower BCD digit
STA 4300H : Store the result
HLT : Terminate program execution