why not just making the counter with a simpel varibel, do we have space for it ?
How would you do that?why not just making the counter with a simpel varibel, do we have space for it ?
Yes as it stands now you have used about 40 bytes of the RAM. And you have 255 bytes of RAM. Goto view and select Momory gauge usage. You can use a few bytes on counter for the rain. No problem. But I would still use a interrupt function for the rain counterwhy not just making the counter with a simpel varibel, do we have space for it ?
Yes, but how ?But I would still use a interrupt function for the rain counter
Will try again later today / tonight.Then RA2 is used as an interrupt pin it will be edge trigged. You can choose if you want to trig an interrupt on rising edge of RA2/INT pin, or Interrupt on falling edge of RA2/INT pin. Using an egde trigged interrupt is much more simple than polling a pin your case. All you have to do is to enable interrupt on RA2 pin and sett the correct edge. Well some programming is also needed. But I have shown you have to add an extra interrupt functionality in the interrupt service routine
#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 set_hour RC4
#define set_minut RC5
#define set_week RC6
#define set_time RC3
#define _XTAL_FREQ 4000000
//global defs
volatile unsigned char week_day;
volatile unsigned char hour, minut, sec, mm;
volatile bit minut_tick, set_time_flag, regn_tick;
volatile bit blink;
const char * const day_of_week_names[] = {"Mandag ",
"Tirsdag",
"Onsdag ",
"Torsdag",
"Fredag ",
"Lordag ",
"Sondag "
};
char timestr[3], regn[4];
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
regn_tick=1;
blink=!blink;
LED=blink;
sec++;
if (sec==2)
{
minut_tick=1;
sec=0;
}
}//we are done here
}
void setup(void)
{ TRISA0=0;
TRISA2=1;
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
//timer0 settings.
//INTCON=0b01100000;
//setup LCD
lcd_init();
lcd_goto(0); // select first line
//set the globals
week_day=5;
minut=0;
sec=0;
hour=0;
minut_tick=0;
blink=0;
regn_tick=0;//clear the tick
}
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(0x47); // Select second line
for (unsigned char i=0;i<7;i++) lcd_putch(day_of_week_names[week_day]);
lcd_goto(0x00);
}
void midnat (void)
{
week_day++;
if (week_day==7) week_day=0;
lcd_format_and_send();
}
void vis_regn (void)
{
lcd_goto(0x00);
utoa(regn, TMR0, 10);
lcd_puts(regn);
lcd_goto(0x00);
}
void ur (void)
{
minut++;
if (minut>=60)
{ minut=0;
hour++;
if (hour>=24)
{ hour=0;
midnat();
}
}
lcd_format_and_send();
}
void stil_ur (void)
{
GIE = 0; // Global interrupt disable as we are setting the time
TMR1ON=0; //timer1 off
sec=0;
TMR1H=0x80;
TMR1L=0;
LED=1;
set_time_flag=1;
do
{
if (!set_hour)
{
hour++;
if (hour==24) hour=0;
lcd_format_and_send();
__delay_ms(200);
}
if (!set_minut)
{
minut++;
if (minut==60) minut=0;
lcd_format_and_send();
__delay_ms(200);
}
if (!set_week)
{
week_day++;
if (week_day==7) week_day=0;
lcd_format_and_send();
__delay_ms(200);
}
} while (!set_time);
GIE = 1; // Global interrupt enable
TMR1ON=1; //timer1 on
set_time_flag=0;
}
void main (void) //hovedprogram
{ setup();
timestr[2]='\0';
lcd_format_and_send();
GIE=1;
TMR1ON=1;
TMR0=0;
while (1)
{
if (minut_tick)
{
ur();
minut_tick=0;
} // end if (minut_tick)
if (!set_time)
{
stil_ur();
}
if (regn_tick)
{
regn_tick=0;
vis_regn();
}
}
}
// flere hvis.....
//end while endless loop
//End main
x=0;
while (x<100)
{if (!set_week) x=0;
__delay_ms(100);
x++;
}
x= eeprom_read(week_day);
lcd_puts(x);
Error [195] FroceMaster display demo_v2.c; 236.1 expression syntax
Error [187] FroceMaster display demo_v2.c; 236.25 too few function arguments
Error [194] FroceMaster display demo_v2.c; 236.25 ")" expected
Error [195] FroceMaster display demo_v2.c; 236.25 expression syntax
Warning [357] FroceMaster display demo_v2.c; 237.11 illegal conversion of integer to pointer
x= eeprom_read(week_day);
utoa(regn, x, 10);
lcd_puts(regn);
if (TMR0>mm);
{
lcd_clear();
lcd_goto(0x00);
lcd_puts("Regn Total : ");
if (TMR0<100)lcd_puts(" ");
if (TMR0<10)lcd_puts(" ");
utoa(regn, TMR0, 10);
mm=TMR0;
eeprom_write(31,TMR0);
lcd_puts(regn);
lcd_puts(" MM");
Then you have probably not done it correct Most probably placed the LCD function in the wrong placeWas just now thinking the same, couse it do not work correct
From the top of head. Do something like this then the day change. Here I have assumed that you have total rain data back log of seven daysTMR0 is total counter.
is it something like, i store total i EE, at midnight, and the daily readout must then be
something like (totalrain - Stored at midnigt) = today ....
void rain_FIFO (void)
{
unsigned char data;
unsigned char target;
for(target=6;target!=0;target--)
{
data=EEPROM_READ(target-1);
EEPROM_WRITE(target,data);
}
EEPROM_WRITE(0,TMR0);
}