Temperature

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Hi
wrote to eeprom each day at midnight
read from eeprom. Each time there came rain and at midnight
and read from eeprom if i check the past 30 days

on the 16f1509 i will read/ write at midnight
and when selecting one of the 30 past days
amount of rain will only be saved each day at midnight
 

spinnaker

Joined Oct 29, 2009
7,830
Hi
wrote to eeprom each day at midnight
read from eeprom. Each time there came rain and at midnight
and read from eeprom if i check the past 30 days

on the 16f1509 i will read/ write at midnight
and when selecting one of the 30 past days
amount of rain will only be saved each day at midnight
Again what does this mean? The 16f1509 does not have EEPROM.

How many times do we need to ask that you express complete thoughts in a full sentence (sentences start with a capital letter end with a period and usually contain a verb and an object.) ? And there is nothing wrong with your English. It is not bad at all. You have plenty of posts in this thread where you were very understandable. You can make yourself understood when you try.
 

t06afre

Joined May 11, 2009
5,934
Hi
wrote to eeprom each day at midnight
read from eeprom. Each time there came rain and at midnight
and read from eeprom if i check the past 30 days

on the 16f1509 i will read/ write at midnight
and when selecting one of the 30 past days
amount of rain will only be saved each day at midnight
What are your current coding attempts regarding flash read/write
 

t06afre

Joined May 11, 2009
5,934
Here is a draft for flash read. Nothing to be afraid of ;)
Rich (BB code):
#include <htc.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include "lcd.h"
//#include <string.h>
__CONFIG (CLKOUTEN_OFF & FCMEN_ON & IESO_OFF & BOREN_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTOSC);//XT
__CONFIG (LVP_ON & LPBOR_OFF & BOREN_ON & STVREN_ON & WRT_OFF);
#define LED RC0
#define set_hour RC7 //knapper
#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;
volatile bit timer_tick, minut_tick,regn_tick,vis;
volatile int mm,i, x,xx,skift;
volatile signed int max,min;
char mintemp[10],maxtemp[10];
unsigned char rain_data[30];
const char rain_mem[]@0x1f80={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
const char * const day_of_week_names[] = {"Mandag ",
                                          "Tirsdag",
                                          "Onsdag ",
                                          "Torsdag",
                                          "Fredag ",
                                          "Lordag ",
                                          "Sondag " 
                                         };
  union { 
unsigned int res;
  char bytes[2];
}ADC;
char ADC_num[5];
float temprature;
void setup(void)
{  
IRCF3=1;//4MHz clock speed
IRCF2=1;
IRCF1=0;
IRCF0=1;
//REGISTER 5-1: OSCCON: OSCILLATOR CONTROL REGISTER
// bit 6-3 IRCF<3:0>: Internal Oscillator Frequency Select bits
//1111 = 16MHz
//1110 = 8MHz
//1101 = 4MHz
//1100 = 2MHz
//1011 = 1MHz
//1010 = 500 kHz(1)
//1001 = 250 kHz(1)
//1000 = 125 kHz(1)
//0111 = 500 kHz (default upon Reset)
//0110 = 250 kHz
//0101 = 125 kHz
//0100 = 62.5 kHz
//001x = 31.25 kHz
//000x = 31kHz LF 
//Port analog / digital
 TRISA=0; //set all port out
 TRISA2=1; // set port 2 in
 TRISA0=1; // set port 0 in.
 TRISB=0; //All port B out
 TRISC=0b11111000;//RC0-RC2 out,RC3-RC7 in,
 GIE = 0;  // Global interrupt disable just in case
 ANSELA = 0b00000001;  // Set PORT AN0 to analog input AN1 to AN7 digital I/O
 //ANSELA=0; // set alle digital. 
 ANSELB=0;
 ANSELC=0;//turn off all analog functions
 
 ///ADCON0=0b00000000;   // select right justify result. ADC port channel 0
//adcon1
ADFM=1; //right justified
//ADCS=100; // fosc/4
ADPREF0=0;
ADPREF1=0;
//ADPREF=00; //vref+ = vdd
TRIGSEL0=0;
TRIGSEL1=0;
TRIGSEL2=0;
TRIGSEL3=0;
CHS0=0;
CHS1=0;
CHS2=0;
CHS3=0;
CHS4=0; // AN0  analog kanal  intern kanal
//timer1 settings
TMR1CS1=1; //CLOCK SOURCE S-ELECTIONS
TMR1CS0=1;
//11 =Timer1 clock source is Capacitive Sensing Oscillator (CAPOSC)
//10 =Timer1 clock source is pin or oscillator:
//If T1OSCEN = 0:
//External clock from T1CKI pin (on the rising edge)
//If T1OSCEN = 1:
//Crystal oscillator on SOSCI/SOSCO pins
//01 =Timer1 clock source is system clock (FOSC)
//00 =Timer1 clock source is instruction clock (FOSC/4)
T1CKPS1=0; // <1:0>: Timer1 Input Clock Prescale Select bits
T1CKPS0=0;
//11 = 1:8 Prescale value
//10 = 1:4 Prescale value
//01 = 1:2 Prescale value
//00 = 1:1 Prescale value
T1OSCEN=1;//LP Oscillator Enable Control bit
//1 = Dedicated Timer1 oscillator circuit enabled
//0 = Dedicated Timer1 oscillator circuit disabled
nT1SYNC=1; //: Timer1 Synchronization Control bit
TMR1ON=0;//: Timer1 On bit
TMR1H = 0x81;     // preset for timer1 MSB register
TMR1L = 0x00;     // preset for timer1 LSB register
TMR1GE=0; // gate for timer1 disable.
//T1GCON: TIMER1 GATE CONTROL REGISTER
//bit 7 TMR1GE: Timer1 Gate Enable bit
//If TMR1ON = 0:
//This bit is ignored
//If TMR1ON = 1:
//1 = Timer1 counting is controlled by the Timer1 gate function
//0 = Timer1 counts regardless of Timer1 gate function
  //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.
 TMR0IE=1; //use timer0 interrupt register.
 TMR0CS=1; // bruger tæller,
 TMR0SE=0; // lav til høj tælning.
 IOCIE=1; // enable interrupt on change
 PSA=1; //not assign prescaler.  
   
// //setup LCD
//lcd_init();
//lcd_goto(0); // select first line
////set the globals
//minut_tick=0;
////other misc settings
 }
void read_flash(void)
{
 //assuming PMADRL/H points to correct adress at this point
      CFGS=0;// Do not select Configuration Space
 RD=1;// Initiate read
 NOP();
       NOP();
 //Data ready now in PMDATH:PMDATL
}
 void prepare_for_flash_write(void)
{
  unsigned char i;
  PMADRH= 0x1F;
 PMADRL= 0x80+28;
       for(i=29;i>1;i--)
  {
    read_flash();
               rain_data=PMDATL;
               PMADRL--;
             }
}
void main (void) 
 {
 setup();   //kører setup
// FLASH_READ(
//   GIE=1;  //interrupt klar
  // TMR1ON=1; // tænder timer1
   TMR0=0;  // timer 0 til 0
   skift=0;  // skift er sec til skift mellem regn og temperatur-
      
  
    while (1)// kører loop
       {
    prepare_for_flash_write();  
        }//end while endless loop 
 }//End main 
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Here is a draft for flash read. Nothing to be afraid of ;)
Rich (BB code):
#include <htc.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include "lcd.h"
//#include <string.h>
__CONFIG (CLKOUTEN_OFF & FCMEN_ON & IESO_OFF & BOREN_OFF & CP_OFF & MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_INTOSC);//XT
__CONFIG (LVP_ON & LPBOR_OFF & BOREN_ON & STVREN_ON & WRT_OFF);
#define LED RC0
#define set_hour RC7 //knapper
#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;
volatile bit timer_tick, minut_tick,regn_tick,vis;
volatile int mm,i, x,xx,skift;
volatile signed int max,min;
char mintemp[10],maxtemp[10];
unsigned char rain_data[30];
const char rain_mem[]@0x1f80={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
const char * const day_of_week_names[] = {"Mandag ",
                                          "Tirsdag",
                                          "Onsdag ",
                                          "Torsdag",
                                          "Fredag ",
                                          "Lordag ",
                                          "Sondag " 
                                         };
  union { 
unsigned int res;
  char bytes[2];
}ADC;
char ADC_num[5];
float temprature;
void setup(void)
{  
IRCF3=1;//4MHz clock speed
IRCF2=1;
IRCF1=0;
IRCF0=1;
//REGISTER 5-1: OSCCON: OSCILLATOR CONTROL REGISTER
// bit 6-3 IRCF<3:0>: Internal Oscillator Frequency Select bits
//1111 = 16MHz
//1110 = 8MHz
//1101 = 4MHz
//1100 = 2MHz
//1011 = 1MHz
//1010 = 500 kHz(1)
//1001 = 250 kHz(1)
//1000 = 125 kHz(1)
//0111 = 500 kHz (default upon Reset)
//0110 = 250 kHz
//0101 = 125 kHz
//0100 = 62.5 kHz
//001x = 31.25 kHz
//000x = 31kHz LF 
//Port analog / digital
 TRISA=0; //set all port out
 TRISA2=1; // set port 2 in
 TRISA0=1; // set port 0 in.
 TRISB=0; //All port B out
 TRISC=0b11111000;//RC0-RC2 out,RC3-RC7 in,
 GIE = 0;  // Global interrupt disable just in case
 ANSELA = 0b00000001;  // Set PORT AN0 to analog input AN1 to AN7 digital I/O
 //ANSELA=0; // set alle digital. 
 ANSELB=0;
 ANSELC=0;//turn off all analog functions
 
 ///ADCON0=0b00000000;   // select right justify result. ADC port channel 0
//adcon1
ADFM=1; //right justified
//ADCS=100; // fosc/4
ADPREF0=0;
ADPREF1=0;
//ADPREF=00; //vref+ = vdd
TRIGSEL0=0;
TRIGSEL1=0;
TRIGSEL2=0;
TRIGSEL3=0;
CHS0=0;
CHS1=0;
CHS2=0;
CHS3=0;
CHS4=0; // AN0  analog kanal  intern kanal
//timer1 settings
TMR1CS1=1; //CLOCK SOURCE S-ELECTIONS
TMR1CS0=1;
//11 =Timer1 clock source is Capacitive Sensing Oscillator (CAPOSC)
//10 =Timer1 clock source is pin or oscillator:
//If T1OSCEN = 0:
//External clock from T1CKI pin (on the rising edge)
//If T1OSCEN = 1:
//Crystal oscillator on SOSCI/SOSCO pins
//01 =Timer1 clock source is system clock (FOSC)
//00 =Timer1 clock source is instruction clock (FOSC/4)
T1CKPS1=0; // <1:0>: Timer1 Input Clock Prescale Select bits
T1CKPS0=0;
//11 = 1:8 Prescale value
//10 = 1:4 Prescale value
//01 = 1:2 Prescale value
//00 = 1:1 Prescale value
T1OSCEN=1;//LP Oscillator Enable Control bit
//1 = Dedicated Timer1 oscillator circuit enabled
//0 = Dedicated Timer1 oscillator circuit disabled
nT1SYNC=1; //: Timer1 Synchronization Control bit
TMR1ON=0;//: Timer1 On bit
TMR1H = 0x81;     // preset for timer1 MSB register
TMR1L = 0x00;     // preset for timer1 LSB register
TMR1GE=0; // gate for timer1 disable.
//T1GCON: TIMER1 GATE CONTROL REGISTER
//bit 7 TMR1GE: Timer1 Gate Enable bit
//If TMR1ON = 0:
//This bit is ignored
//If TMR1ON = 1:
//1 = Timer1 counting is controlled by the Timer1 gate function
//0 = Timer1 counts regardless of Timer1 gate function
  //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.
 TMR0IE=1; //use timer0 interrupt register.
 TMR0CS=1; // bruger tæller,
 TMR0SE=0; // lav til høj tælning.
 IOCIE=1; // enable interrupt on change
 PSA=1; //not assign prescaler.  
 
// //setup LCD
//lcd_init();
//lcd_goto(0); // select first line
////set the globals
//minut_tick=0;
////other misc settings
 }
void read_flash(void)
{
 //assuming PMADRL/H points to correct adress at this point
      CFGS=0;// Do not select Configuration Space
 RD=1;// Initiate read
 NOP();
       NOP();
 //Data ready now in PMDATH:PMDATL
}
 void prepare_for_flash_write(void)
{
  unsigned char i;
  PMADRH= 0x1F;
 PMADRL= 0x80+28;
       for(i=29;i>1;i--)
  {
    read_flash();
               rain_data=PMDATL;
               PMADRL--;
             }
}
void main (void) 
 {
 setup();   //kører setup
// FLASH_READ(
//   GIE=1;  //interrupt klar
  // TMR1ON=1; // tænder timer1
   TMR0=0;  // timer 0 til 0
   skift=0;  // skift er sec til skift mellem regn og temperatur-
 
 
    while (1)// kører loop
       {
    prepare_for_flash_write();  
        }//end while endless loop 
 }//End main 


Ok,, now i will have the "data" from Flash, read into 29 var. called rain_data(1) until rain_data(29) or am i wrong ?
then i can make the "selcetion" of days.
But that will next year ;)

Today i have been improved the accrasy of the temprature.
making it read every second for 3 sec., and got the average, and compared it to "now" reading, and if not more than 0.5 degrees difference, it will show temprature, if not, it will do another round.

:D:DHAPPY NEW YEAR.:D:D
 
Last edited:

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
That I did not quite understand? But let us take that next year
Sorry , my mistake,
i mean that the code you posted, Flash_read and prepare_for_flash_read
should be enough to read out from flash, but have no data in it yet.

Still i need to figure out something with bad reading from AN0.
When i have 4 reading in a row with same result +-2,5 degree.
and that one i way off, it shouldnt register as ok. but that something i have to work with
 
Top