You are on page 1of 10

Interfacing LED dot matrix Display (5*7) WITH PIC16F877A

Write a program for displaying 3-character scrolling message. The three characters to be
displayed are ‘IST’. Character should move from left to right.

Code:

#include<16f877a.h>
#fuses XT,NOWDT
#use delay(clock=4000000)
#byte PORTB=0X6
#byte PORTC=0X7
#byte PORTD=0X8
#byte TRISB=0X86
#byte TRISC=0X87
#byte TRISD=0X88

void main()
{int i=0;
PORTB=0;
PORTC=0;
PORTD=0;
TRISB=0;
TRISC=0;
TRISD=0;

while(1)
{
for(i=0;i<24;i++)
{ PORTB=0;
PORTC=1;
PORTD=0B11111111;
delay_ms(2);

PORTC=2;
PORTD=0B11111111;
delay_ms(2);

PORTC=4;
PORTD=0B11111111;
delay_ms(2);

PORTC=8;
PORTD=0B11111111;
delay_ms(2);

PORTC=16;
PORTD=0B11111111;
delay_ms(2);

PORTC=32;
PORTD=0B11111111;;
delay_ms(2);

PORTC=64;
PORTD=0B11111111;
delay_ms(2);

PORTC=128;
PORTD=0B11111111;
delay_ms(2);
PORTC=0;
PORTB=1;
PORTD=0B11111111;
delay_ms(2);

PORTB=2;
PORTD=0B11111111;
delay_ms(2);

PORTB=4;
PORTD=0xFF;
delay_ms(2);

PORTB=8;
PORTD=0xBE;
delay_ms(2);

PORTB=16;
PORTD=0x80;
delay_ms(2);

PORTB=32;
PORTD=0xBE;
delay_ms(2);

PORTB=64;
PORTD=0xFF;
delay_ms(2);
PORTB=128;

}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

for(i=0;i<24;i++)
{ PORTB=0;
PORTC=1;
PORTD=0B11111111;
delay_ms(2);

PORTC=2;
PORTD=0B11111111;
delay_ms(2);

PORTC=4;
PORTD=0B11111111;
delay_ms(2);

PORTC=8;
PORTD=0B11111111;
delay_ms(2);

PORTC=16;
PORTD=0B11111111;
delay_ms(2);

PORTC=32;
PORTD=0xFF;
delay_ms(2);

PORTC=64;
PORTD=0xBE;
delay_ms(2);

PORTC=128;
PORTD=0x80;
delay_ms(2);
PORTC=0;
delay_ms(2);
PORTB=1;
PORTD=0xBE;
delay_ms(2);

PORTB=2;
PORTD=0xFF;
delay_ms(2);

PORTB=4;
PORTD=0xB9;
delay_ms(2);

PORTB=8;
PORTD=0x36;
delay_ms(2);

PORTB=16;
PORTD=0x36;
delay_ms(2);

PORTB=32;
PORTD=0x36;
delay_ms(2);

PORTB=64;
PORTD=0xCE;
delay_ms(2);
PORTB=128;

}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
for(i=0;i<24;i++)
{
PORTB=0;
PORTC=1;
PORTD=0xFF;
delay_ms(2);

PORTC=2;
PORTD=0xBE;
delay_ms(2);

PORTC=4;
PORTD=0x80;
delay_ms(2);

PORTC=8;
PORTD=0xBE;
delay_ms(2);

PORTC=16;
PORTD=0xFF;
delay_ms(2);

PORTC=32;
PORTD=0xB9;
delay_ms(2);

PORTC=64;
PORTD=0x36;
delay_ms(2);

PORTC=128;
PORTD=0x36;
delay_ms(2);
PORTC=0;
delay_ms(2);
PORTB=1;
PORTD=0x36;
delay_ms(2);

PORTB=2;
PORTD=0xCE;
delay_ms(2);

PORTB=4;
PORTD=0xFE;
delay_ms(2);

PORTB=8;
PORTD=0xFE;
delay_ms(2);

PORTB=16;
PORTD=0x80;
delay_ms(2);

PORTB=32;
PORTD=0xFE;
delay_ms(2);

PORTB=64;
PORTD=0xFE;
delay_ms(2);
PORTB=128;
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
for(i=0;i<24;i++)
{
PORTB=0;
PORTC=1;
PORTD=0xB9;
delay_ms(2);

PORTC=2;
PORTD=0x36;
delay_ms(2);

PORTC=4;
PORTD=0x36;
delay_ms(2);

PORTC=8;
PORTD=0x36;
delay_ms(2);

PORTC=16;
PORTD=0xCE;
delay_ms(2);

PORTC=32;
PORTD=0xFE;
delay_ms(2);

PORTC=64;
PORTD=0xFE;
delay_ms(2);

PORTC=128;
PORTD=0x80;
delay_ms(2);
PORTC=0;
delay_ms(2);
PORTB=1;
PORTD=0xFE;
delay_ms(2);

PORTB=2;
PORTD=0xFE;
delay_ms(2);

PORTB=4;
PORTD=0B11111111;
delay_ms(2);

PORTB=8;
PORTD=0B11111111;
delay_ms(2);

PORTB=16;
PORTD=0B11111111;
delay_ms(2);

PORTB=32;
PORTD=0B11111111;
delay_ms(2);

PORTB=64;
PORTD=0B11111111;
delay_ms(2);
PORTB=128;
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
for(i=0;i<24;i++)
{
PORTB=0;
PORTC=1;
PORTD=0xFE;
delay_ms(2);

PORTC=2;
PORTD=0xFE;
delay_ms(2);

PORTC=4;
PORTD=0x80;
delay_ms(2);

PORTC=8;
PORTD=0xFE;
delay_ms(2);

PORTC=16;
PORTD=0xFE;
delay_ms(2);

PORTC=32;
PORTD=0B11111111;
delay_ms(2);
PORTC=64;
PORTD=0B11111111;
delay_ms(2);

PORTC=128;
PORTD=0B11111111;
delay_ms(2);
PORTC=0;
delay_ms(2);
PORTB=1;
PORTD=0B11111111;
delay_ms(2);

PORTB=2;
PORTD=0B11111111;
delay_ms(2);

PORTB=4;
PORTD=0B11111111;
delay_ms(2);

PORTB=8;
PORTD=0B11111111;
delay_ms(2);

PORTB=16;
PORTD=0B11111111;
delay_ms(2);

PORTB=32;
PORTD=0B11111111;
delay_ms(2);

PORTB=64;
PORTD=0B11111111;
delay_ms(2);
PORTC=128;
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
for(i=0;i<24;i++)
{
PORTB=0;
PORTC=1;
PORTD=0B11111111;
delay_ms(2);
PORTC=2;
PORTD=0B11111111;
delay_ms(2);

PORTC=4;
PORTD=0B11111111;
delay_ms(2);

PORTC=8;
PORTD=0B11111111;
delay_ms(2);

PORTC=16;
PORTD=0B11111111;
delay_ms(2);

PORTC=32;
PORTD=0B11111111;;
delay_ms(2);

PORTC=64;
PORTD=0B11111111;
delay_ms(2);

PORTC=128;
PORTD=0B11111111;
delay_ms(2);
PORTC=0;
delay_ms(2);
PORTB=1;
PORTD=0B11111111;
delay_ms(2);

PORTB=2;
PORTD=0B11111111;
delay_ms(2);

PORTB=4;
PORTD=0B11111111;
delay_ms(2);

PORTB=8;
PORTD=0B11111111;
delay_ms(2);
PORTB=16;
PORTD=0B11111111;
delay_ms(2);

PORTB=32;
PORTD=0B11111111;
delay_ms(2);

PORTB=64;
PORTD=0B11111111;
delay_ms(2);
PORTB=128;
}
delay_ms(1000);
}
}