Saturday, August 30, 2008
Just another 99 Minute Electronics Timer
I have designed 99 Minute Electronics Timer using PIC16F627a. I will post the detail later (again).
Topics:
Microcontroller
Monday, August 18, 2008
5x7 Led Dot Matrix Clock using only one chip
I use a microcontroller, pic16f887, as the brain of this clock. The time displays on a small 5x7 led dot matrix in lanscape mode. The chip is running with the internal oscillator at 4.0 MHz. External frequency 32.768KHz for time base is getting from DS32KHz. The accuracy is not that impressive, ~2 sec/day.
The schematic and source code in MikroC will be posted here. Please stay tuned!!
--- Update --
Source Code is now available at 5x7 dot matrix clock code
Schematic is available at 5x7 Dot Matrix clock schematic
Topics:
Clock,
Dot Matrix,
Microcontroller
Wednesday, August 13, 2008
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);
}
}
#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.
Topics:
Clock,
Dot Matrix,
Microcontroller,
MikroC,
Schematic
DS1307 : Setting Time
There is a question from charlie about how to set time in DS1307 . The code here shows how to write time to DS1307. My C compiler is MikroC 8.0.
It is your task to incorporate the code with buttons for setting time. I have written code for taking care of the buttons but there are some bugs so I cannot show it now.
void write_ds1307(unsigned short address,unsigned short w_data)
{
I2C_Start(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
I2C_Wr(0xD0); // send byte via I2C (device address + W)
I2C_Wr(address); // send byte (address of DS1307 location)
I2C_Wr(w_data); // send data (data to be written)
I2C_Stop(); // issue I2C stop signal
}
//Set Time
write_ds1307(0,0x80); //Reset second to 0 sec. and stop Oscillator
write_ds1307(1,0x27); //write min 27
write_ds1307(2,0x14); //write hour 14
write_ds1307(3,0x02); //write day of week 2:Monday
write_ds1307(4,0x17); // write date 17
write_ds1307(5,0x06); // write month 6 June
write_ds1307(6,0x08); // write year 8 --> 2008
write_ds1307(7,0x10); //SQWE output at 1 Hz
write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator
{
I2C_Start(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
I2C_Wr(0xD0); // send byte via I2C (device address + W)
I2C_Wr(address); // send byte (address of DS1307 location)
I2C_Wr(w_data); // send data (data to be written)
I2C_Stop(); // issue I2C stop signal
}
//Set Time
write_ds1307(0,0x80); //Reset second to 0 sec. and stop Oscillator
write_ds1307(1,0x27); //write min 27
write_ds1307(2,0x14); //write hour 14
write_ds1307(3,0x02); //write day of week 2:Monday
write_ds1307(4,0x17); // write date 17
write_ds1307(5,0x06); // write month 6 June
write_ds1307(6,0x08); // write year 8 --> 2008
write_ds1307(7,0x10); //SQWE output at 1 Hz
write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator
It is your task to incorporate the code with buttons for setting time. I have written code for taking care of the buttons but there are some bugs so I cannot show it now.
Topics:
Clock,
DS1307,
Microcontroller,
MikroC,
PIC16F887,
Source Code
Subscribe to:
Posts (Atom)