Wednesday, August 13, 2008

Cool Clock with HDSP-2111 Display

Cool Clock with HDSP-2111 Display
Just a picture of my clock using PIC16f877a microcontroller (the project was done before I discovered PIC16f887). The HDSP-2111 (or HDSP-211x) display is a very cool led dot matrix. The interface is very easy. The quick and dirty code (no time setting function)is here.
//PIC16f877a PIC Microcontroller, 20MHz
#define Address PORTA
#define Data PORTB
#define WR PORTC.F5
#define A3 PORTC.F4
#define RST PORTC.F3

typedef unsigned short uns8;
uns8 hour;
uns8 minute;
uns8 second;
uns8 cnt;
uns8 min_cnt;
uns8 Digit[24];
uns8 i;
uns8 j;
uns8 pause_timer;
void setup();
void Init_Display();
void set_time(uns8 hr,uns8 min,uns8 sec);
void make_time();
void show_time();
void scroll();
void interrupt() {
PIR1.TMR1IF = 0; // clears TMR1IF
TMR1H = 0x0B; //Start at 0x0BDC (to overflow at 62500)
TMR1L = 0xDC;
// TMR1 starts at 0x0BDC = 3036 to make TMR1 counts to 62500 and
// overflows in every 0.1 sec
// Math: 1/5000000*8*62500 = 0.1
// 1/5000000 : time for 20MHz crystal (internal clock will be 20/4 = 1MHz)
// 8: prescaler
// 62500: TMR1 counts to 62500
// Counting number of overflows to 10 will get 1 sec.
cnt++ ; // Increment counter
}
void main(){
setup();
set_time(17,40,0); //Set time
j=0;
pause_timer = 0;

while(1){
if(cnt > 9){ //Count to 10 for 1 sec.
cnt = 0;
make_time();
show_time();
}

for(i=0;i<8;i++){
Address = i;
Data = Digit[j+i];
WR = 0;
WR = 1;
}

j++;

if(j == 9 && pause_timer<300){
j=8;
pause_timer++;
}

if(pause_timer == 100){
pause_timer = 0;
j++;
}

if(j>15){
j=0;
}

Delay_ms(200);
}

}

void setup(){
CMCON = 0x07; //Digital port
TRISA = 0;
TRISB = 0;
TRISC = 0x01; //RC7=input
Data.F7 = 0;
T1CON = 0x31; // Prescaler 1:8
PIE1.TMR1IE = 1; // enable interupt
INTCON = 0xC0; // Set GIE, PEIE
TMR1L = 0xDC;
TMR1H = 0x0B;
Init_Display();

for(i=0;i<24;i++){
Digit[i] = ' ';
}
}

void Init_Display(){
WR = 1;
RST = 0;
Delay_ms(10);
RST = 1;
Delay_ms(10);
Data = 6; //27% Brightness
A3 = 0;
WR = 0;
WR = 1;
A3 = 1;
}

void set_time(uns8 hr, uns8 min, uns8 sec){
second=sec;
minute=min;
hour=hr;
}

void make_time(){
if(second < 59){
second = second++;
}else{

second = 0;
minute = minute++;
}

if(minute > 59) {
minute = 0;
hour = hour++;

}

if(hour > 23){
hour = 0;
}

Digit[8] = hour/10+'0';
Digit[9] = hour%10+'0';
Digit[10] = ':';
Digit[11] = minute/10 + '0';
Digit[12] = minute%10 + '0';
Digit[13] = ':';
Digit[14] = second/10 + '0';
Digit[15] = second%10 + '0';
}

void show_time(){
for(i=0;i<8;i++){
Address = i;
Data = Digit[i];
WR = 0;
WR = 1;
}
}

void scroll(){

for(j=8;j<16;j++){

for(i=0;i<8;i++){

Address = i;
Data = Digit[j+i];
WR = 0;
WR = 1;

}
Delay_ms(200);
}
}



Circuit diagram is here.

Schematic of Clock with HDSP-2111 Display

1 comment:

Sonny said...

Just curious - what compiler did you use for this?