damm, have to edit it again, have just rewired it all.
ok, try again, tomorrow after work,
ok, try again, tomorrow after work,
Or you could change the code of course. The switches will not do any harm if mounteddamm, have to edit it again, have just rewired it all.
ok, try again, tomorrow after work,
Nice and small project. Your crystal is to big to be clock crytsal. Did you use timer 1 , and the compare module approach? And what was your timer tick interrupt rate?I just checked my old 16F88 single chip Charlieplexed Clock/Calendar/Timer project which was written in BoostC and it only uses 711 words of program memory
The crystal is 16-MHz (what I had on hand) and I'm using 1-msec (1-kHz) TMR2 interrupts to drive the display and the RTC code. I've attached the source if anyone would like to take a peek.Nice and small project. Your crystal is to big to be clock crytsal. Did you use timer 1 , and the compare module approach? And what was your timer tick interrupt rate?MMcLaren said:I just checked my old 16F88 single chip Charlieplexed Clock/Calendar/Timer project (written in BoostC) and it only uses 711 words of program memory...
Good to hear. Any questions. The setup is a framework for a clock. It has all the main components.board rebuild and ready,
Works ok, have study it a lot, have change the text and make i run backwards in days.
void lcd_format_and_send(void)
{ blink=!blink;
LED=blink;
if (blink) lcd_puts("Next LED will be off");
else lcd_puts("Next LED will be on ");
lcd_goto(0x40); // Select second line
//lcd_puts("day of week ");
//lcd_putch(week_day+48);
lcd_puts(day_of_week_names[week_day]);
lcd_goto(0x00);
}
void skriv(void)
{ week_day++;
if (week_day==7) week_day=0;
lcd_format_and_send();//send time to LCD
}
void main (void)
{ setup();
GIE=1;
TMR1ON=1;
while (1)
{
if (timer_tick)
{
skriv();
timer_tick=0;
} // end if (timer_tick) Memo to my self put all this in sub function
} //end while endless loop
}//End main
if (blink) lcd_puts(minut);
volatile int time,minut,sec;
char sec[3];
sec[0]=53;
sec[1]=57;
sec[2]=0;
lcd_puts(sec);
const char * ascii_time[] = {"00","01"........"58","59"};
unsigned char seconds;
lcd_puts(ascii_time[seconds]);
char timestr[3]
void main(void)
{timestr[2]='\0';
.
.
.
utoa(timestr, hours, 10);
lcd_puts(timestr);
lcd_puts(":");
utoa(timestr, minutes, 10);
}
void lcd_format_and_send(void)
{
lcd_goto(0x08);
utoa(timestr, hour, 10);
if (hour<10)lcd_puts("0");
lcd_puts(timestr);
lcd_puts(":");
utoa(timestr, minut, 10);
if (minut<10)lcd_puts("0");
lcd_puts(timestr);
lcd_goto(0x40); // Select second line
lcd_puts(day_of_week_names[week_day]);
}
SureCan you post the full program?
///*// Config Register: CONFIG
//#define CONFIG 0x2007
//// Oscillator Selection bits
//// RC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, RC on RA5/OSC1/CLKIN
//#define FOSC_EXTRCCLK 0xFFFF
//// RCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, RC on RA5/OSC1/CLKIN
//#define FOSC_EXTRCIO 0xFFFE
//// INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
//#define FOSC_INTRCCLK 0xFFFD
//// INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
//#define FOSC_INTRCIO 0xFFFC
//// EC: I/O function on RA4/OSC2/CLKOUT pin, CLKIN on RA5/OSC1/CLKIN
//#define FOSC_EC 0xFFFB
//// HS oscillator: High-speed crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
//#define FOSC_HS 0xFFFA
//// XT oscillator: Crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
//#define FOSC_XT 0xFFF9
//// LP oscillator: Low-power crystal on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
//#define FOSC_LP 0xFFF8
//// Watchdog Timer Enable bit
//// WDT enabled
//#define WDTE_ON 0xFFFF
//// WDT disabled and can be enabled by SWDTEN bit of the WDTCON register
//#define WDTE_OFF 0xFFF7
//// Power-up Timer Enable bit
//// PWRT disabled
//#define PWRTE_OFF 0xFFFF
//// PWRT enabled
//#define PWRTE_ON 0xFFEF
//// MCLR Pin Function Select bit
//// MCLR pin function is MCLR
//#define MCLRE_ON 0xFFFF
//// MCLR pin function is digital input, MCLR internally tied to VDD
//#define MCLRE_OFF 0xFFDF
//// Code Protection bit
//// Program memory code protection is disabled
//#define CP_OFF 0xFFFF
//// Program memory code protection is enabled
//#define CP_ON 0xFFBF
//// Data Code Protection bit
//// Data memory code protection is disabled
//#define CPD_OFF 0xFFFF
//// Data memory code protection is enabled
//#define CPD_ON 0xFF7F
//// Brown-out Reset Selection bits
//// BOR enabled
//#define BOREN_ON 0xFFFF
//// BOR enabled during operation and disabled in Sleep
//#define BOREN_NSLEEP 0xFEFF
//// BOR controlled by SBOREN bit of the PCON register
//#define BOREN_SBODEN 0xFDFF
//// BOR disabled
//#define BOREN_OFF 0xFCFF
//// Internal External Switchover bit
//// Internal External Switchover mode is enabled
//#define IESO_ON 0xFFFF
//// Internal External Switchover mode is disabled
//#define IESO_OFF 0xFBFF
//// Fail-Safe Clock Monitor Enabled bit
//// Fail-Safe Clock Monitor is enabled
//#define FCMEN_ON 0xFFFF
//// Fail-Safe Clock Monitor is disabled
//#define FCMEN_OFF 0xF7FF*/
#include <htc.h>
//#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
__CONFIG (FCMEN_ON & IESO_OFF & BOREN_OFF & CPD_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTRCIO);
#define LED RC0
#define _XTAL_FREQ 4000000
//global defs
volatile unsigned char week_day;
volatile unsigned char hour, minut, sec;
volatile bit timer_tick, minut_tick;
volatile bit blink;
char timestr[3];
const char * const day_of_week_names[] = {"Mandag ",
"Tirsdag",
"Onsdag ",
"Torsdag",
"Fredag ",
"Lordag ",
"Sondag "
};
static void interrupt
isr(void) // Here is interrupt function - the name is
// unimportant.
{
if(TMR1IF)
{// Was this a timer overflow?
TMR1IF=0;//Clear interrupt flag, ready for next
TMR1H=0x80;
//If we set TMR1 to start at 0x8000 (32768), the TMR1 will overflow every 1 second
timer_tick=1;
blink=!blink;
LED=blink;
sec++;
if (sec==60)
{
minut_tick=1;
sec=0;
}
}//we are done here
}
void setup(void)
{ TRISA0=0;
TRISC=0b01111000;//RC0-RC2 out,RC3-RC6 in,RC7 out
TRISB=0; //All port B output
GIE = 0; // Global interrupt disable just in case
ANSEL=0;
ANSELH=0;//turn off all analog functions
//timer1 settings
TMR1H=0x80;
TMR1L=0;
//T1CON=0b00000110;//used during debug
T1CON=0b00001110;
// See datasheet REGISTER 6-1: T1CON: TIMER 1 CONTROL REGISTER
// bit order T1GINV TMR1GE T1CKPS1 T1CKPS0 T1OSCEN !T1SYNC TMR1CS TMR1ON
//Timer1 Interrupt prepare
TMR1IE=1;// PIE1 register
PEIE=1; //INTCON register
PIR1=0; // Clear all bits PERIPHERAL INTERRUPT REQUEST REGISTER 1
//todo now in order to generate interrupt GEI=1 and TMR1ON=1
//setup LCD
lcd_init();
lcd_goto(0); // select first line
//set the globals
week_day=4;
minut=0;
sec=0;
hour=0;
timer_tick=0;
blink=0;
//other misc settings
timer_tick=0;//clear the tick
}
void lcd_format_and_send(void)
{
week_day=4;
lcd_goto(0x08);
utoa(timestr, hour, 10);
if (hour<10)lcd_puts("0");
lcd_puts(timestr);
lcd_puts(":");
utoa(timestr, minut, 10);
if (minut<10)lcd_puts("0");
lcd_puts(timestr);
lcd_goto(0x40); // Select second line
lcd_puts(day_of_week_names[week_day]);
}
void ur (void)
{
minut++;
if (minut>=60)
{ minut=0;
hour++;
if (hour>=24)
{ hour=0;
// midnat();
}
}
lcd_format_and_send();
}
void main (void)
{ setup();
timestr[2]='\0';
GIE=1;
TMR1ON=1;
while (1)
{
if (minut_tick)
{
ur();
//skriv();
minut_tick=0;
} // end if (minut_tick)
// flere hvis.....
} //end while endless loop
}//End main