#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
void ENABLE()
{
output_low(PIN_C0);
}
void DISABLE()
{
output_high(PIN_C0);
}
void LATCH()
{
output_high(PIN_C1);
}
void COL_CONTROL_H(int i)
{
if(i==0)
{
output_high(PIN_D0);
}
else if(i==1)
{
output_high(PIN_D1);
}
else if(i==2)
{
output_high(PIN_D2);
}
else if(i==3)
{
output_high(PIN_D3);
}
else if(i==4)
{
output_high(PIN_D4);
}
else if(i==5)
{
output_high(PIN_D5);
}
else if(i==6)
{
output_high(PIN_D6);
}
}
void COL_CONTROL_L(int i)
{
if(i==0)
{
output_low(PIN_D0);
}
else if(i==1)
{
output_low(PIN_D1);
}
else if(i==2)
{
output_low(PIN_D2);
}
else if(i==3)
{
output_low(PIN_D3);
}
else if(i==4)
{
output_low(PIN_D4);
}
else if(i==5)
{
output_low(PIN_D5);
}
else if(i==6)
{
output_low(PIN_D6);
}
}
void ROW_5H()
{
output_high(PIN_C2);
}
void ROW_4H()
{
output_high(PIN_C3);
}
void ROW_3H()
{
output_high(PIN_C4);
}
void ROW_2H()
{
output_high(PIN_C5);
}
void ROW_1H()
{
output_high(PIN_C6);
}
void ROW_5L()
{
output_low(PIN_C2);
}
void ROW_4L()
{
output_low(PIN_C3);
}
void ROW_3L()
{
output_low(PIN_C4);
}
void ROW_2L()
{
output_low(PIN_C5);
}
void ROW_1L()
{
output_low(PIN_C6);
}
void DELAY_SS()
{
DISABLE();
delay_us(250);
ENABLE();
delay_us(250);
}
void CHAR_MAP()
{
int i=0,j;
while(1)
{
for(i=0;i<25;i++)
{
/*
//A
COL_CONTROL_L(i);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
COL_CONTROL_L(i+1);
ROW_5H();
ROW_3H();
delay_us(50);
COL_CONTROL_H(i+1);
ROW_5L();
ROW_3L();
delay_us(50);
COL_CONTROL_L(i+2);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i+2);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
DELAY_SS();
//B
COL_CONTROL_L(i);
ROW_1H();
ROW_2H();
ROW_3H():
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i);
ROW_1L();
ROW_2L();
ROW_3L():
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i+1);
ROW_1H();
ROW-3H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i+1);
ROW_1L();
ROW-3L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i+2);
ROW_2H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i+2);
ROW_2L();
ROW_4L();
delay_us(50);
DELAY_SS();
//C
COL_CONTROL_L(i);
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i);
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
COL_CONTROL_L(i+1);
ROW_1H();
ROW_5H();
delay_us(50);
COL_OCNTROL_H(i+1);
ROW_1L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i+2);
ROW_1H();
ROW_5H();
delay_us(50);
COL_OCNTROL_H(i+2);
ROW_1L();
ROW_5L();
delay_us(50);
DELAY_SS();
//D
COL_CONTROL_L(i);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
*/
//H
COL_CONTROL_L(i+2);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i+2);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i+1);
ROW_3H();
delay_us(50);
COL_CONTROL_H(i+1);
ROW_3L();
delay_us(50);
COL_CONTROL_L(i);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
DELAY_SS();
//E
COL_CONTROL_L(i-2);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i-2);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i-3);
ROW_5H();
ROW_3H();
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-3);
ROW_5L();
ROW_3L();
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-4);
ROW_5H();
ROW_3H();
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-4);
ROW_5L();
ROW_3L();
ROW_1L();
delay_us(50);
DELAY_SS();
//L
COL_CONTROL_L(i-6);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i-6);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i-7);
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-7);
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-8);
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-8);
ROW_1L();
delay_us(50);
DISABLE();
delay_us(650);
ENABLE();
DELAY_SS();
//L
COL_CONTROL_L(i-10);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i-10);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i-11);
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-11);
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-12);
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-12);
ROW_1L();
delay_us(50);
//O
COL_CONTROL_L(i-14);
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i-14);
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
COL_CONTROL_L(i-15);
ROW_5H();
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-15);
ROW_5L();
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-16);
ROW_5H();
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-16);
ROW_5L();
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-17);
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i-17);
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
DELAY_SS();
}
}
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
ENABLE();
COM();
LATCH();
CHAR_MAP();
}
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=20000000)
void ENABLE()
{
output_low(PIN_C0);
}
void DISABLE()
{
output_high(PIN_C0);
}
void LATCH()
{
output_high(PIN_C1);
}
void COL_CONTROL_H(int i)
{
if(i==0)
{
output_high(PIN_D0);
}
else if(i==1)
{
output_high(PIN_D1);
}
else if(i==2)
{
output_high(PIN_D2);
}
else if(i==3)
{
output_high(PIN_D3);
}
else if(i==4)
{
output_high(PIN_D4);
}
else if(i==5)
{
output_high(PIN_D5);
}
else if(i==6)
{
output_high(PIN_D6);
}
}
void COL_CONTROL_L(int i)
{
if(i==0)
{
output_low(PIN_D0);
}
else if(i==1)
{
output_low(PIN_D1);
}
else if(i==2)
{
output_low(PIN_D2);
}
else if(i==3)
{
output_low(PIN_D3);
}
else if(i==4)
{
output_low(PIN_D4);
}
else if(i==5)
{
output_low(PIN_D5);
}
else if(i==6)
{
output_low(PIN_D6);
}
}
void ROW_5H()
{
output_high(PIN_C2);
}
void ROW_4H()
{
output_high(PIN_C3);
}
void ROW_3H()
{
output_high(PIN_C4);
}
void ROW_2H()
{
output_high(PIN_C5);
}
void ROW_1H()
{
output_high(PIN_C6);
}
void ROW_5L()
{
output_low(PIN_C2);
}
void ROW_4L()
{
output_low(PIN_C3);
}
void ROW_3L()
{
output_low(PIN_C4);
}
void ROW_2L()
{
output_low(PIN_C5);
}
void ROW_1L()
{
output_low(PIN_C6);
}
void DELAY_SS()
{
DISABLE();
delay_us(250);
ENABLE();
delay_us(250);
}
void CHAR_MAP()
{
int i=0,j;
while(1)
{
for(i=0;i<25;i++)
{
/*
//A
COL_CONTROL_L(i);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
COL_CONTROL_L(i+1);
ROW_5H();
ROW_3H();
delay_us(50);
COL_CONTROL_H(i+1);
ROW_5L();
ROW_3L();
delay_us(50);
COL_CONTROL_L(i+2);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i+2);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
DELAY_SS();
//B
COL_CONTROL_L(i);
ROW_1H();
ROW_2H();
ROW_3H():
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i);
ROW_1L();
ROW_2L();
ROW_3L():
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i+1);
ROW_1H();
ROW-3H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i+1);
ROW_1L();
ROW-3L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i+2);
ROW_2H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i+2);
ROW_2L();
ROW_4L();
delay_us(50);
DELAY_SS();
//C
COL_CONTROL_L(i);
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i);
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
COL_CONTROL_L(i+1);
ROW_1H();
ROW_5H();
delay_us(50);
COL_OCNTROL_H(i+1);
ROW_1L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i+2);
ROW_1H();
ROW_5H();
delay_us(50);
COL_OCNTROL_H(i+2);
ROW_1L();
ROW_5L();
delay_us(50);
DELAY_SS();
//D
COL_CONTROL_L(i);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
*/
//H
COL_CONTROL_L(i+2);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i+2);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i+1);
ROW_3H();
delay_us(50);
COL_CONTROL_H(i+1);
ROW_3L();
delay_us(50);
COL_CONTROL_L(i);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
DELAY_SS();
//E
COL_CONTROL_L(i-2);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i-2);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i-3);
ROW_5H();
ROW_3H();
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-3);
ROW_5L();
ROW_3L();
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-4);
ROW_5H();
ROW_3H();
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-4);
ROW_5L();
ROW_3L();
ROW_1L();
delay_us(50);
DELAY_SS();
//L
COL_CONTROL_L(i-6);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i-6);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i-7);
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-7);
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-8);
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-8);
ROW_1L();
delay_us(50);
DISABLE();
delay_us(650);
ENABLE();
DELAY_SS();
//L
COL_CONTROL_L(i-10);
ROW_1H();
ROW_2H();
ROW_3H();
ROW_4H();
ROW_5H();
delay_us(50);
COL_CONTROL_H(i-10);
ROW_1L();
ROW_2L();
ROW_3L();
ROW_4L();
ROW_5L();
delay_us(50);
COL_CONTROL_L(i-11);
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-11);
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-12);
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-12);
ROW_1L();
delay_us(50);
//O
COL_CONTROL_L(i-14);
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i-14);
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
COL_CONTROL_L(i-15);
ROW_5H();
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-15);
ROW_5L();
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-16);
ROW_5H();
ROW_1H();
delay_us(50);
COL_CONTROL_H(i-16);
ROW_5L();
ROW_1L();
delay_us(50);
COL_CONTROL_L(i-17);
ROW_2H();
ROW_3H();
ROW_4H();
delay_us(50);
COL_CONTROL_H(i-17);
ROW_2L();
ROW_3L();
ROW_4L();
delay_us(50);
DELAY_SS();
}
}
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
ENABLE();
COM();
LATCH();
CHAR_MAP();
}
dear vivek,
ReplyDeletein VOID COLCONTROL_H(int i) function instead of 'if.. Else' can't we use switch statement? I think it makes code much simple and comprehesive
anyway good effort buddy..