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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
| *********************************************
*//voila ce que je voudrais******************
*//si 0C=20h , 00,h=? 02h=?etc ,juqu à 24h=?*
*et comment les atrubier au port RB7 à RB0 *
*ou se trouve les ports R7 à RB0 dans EEPROM*
*et comment définir les heurs *
*********************************************
VOILA le fiechier RTC6C en question
/// F84 Miniature Realtime Controller V1.0
// PIC16F84 LP Xtal 32768Hz runs rtc.c
// The RTC.C was compiled by PCW PIC C Compiler V2.266
// April 10,1999
// Copyright(C) 1999 Wichit Sirichote
// May 5, 2004 fixed bug on minute converting!
// July 23, 2004 add reset port B to high after pressed S1
#include <RTC.H>
#fuses LP,NOPROTECT,NOWDT // must include this line !!
// set clock to 19:00 when press set time button once
// change below for your convenient
//#define setHour 19
//#define setMin 0
// May 16 2000 modify set hour and set min read from eeprom space
// set clock to set hour and set min resided in eeprom
// address 213E set hour
// address 213F set min
// access two bytes by using built-in function read_eeprom(62) and read_eeprom(63)
// Scheduler format in eeprom
/*
address data
2100 19 00 04 19 01 00 FF FF as seen in Nigel's data memory
2108 FF FF FF FF FF FF FF FF window
...........
meaning
2100 19 ; set hour
2101 00 ; set min
2102 04 ; output byte to be sent to port_B, '1' turn on, '0' off
....
FF byte is end of stored PGM
output byte use '1' means turn the device on
RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0
OUTPUT NC 5 4 3 2 1 NC NC
NOTE! output byte seen in Nigel's EEPROM window must be HEXadecimal, e.g.
Suppose at 20:00 turn output 1 and 2 on, the output byte must be
0 0 0 0 1 1 0 0 = 0C
*/
// rename i/o devices
#define LED PIN_B0
#define KEY PIN_A2
// variables declaration
char sec,min,hour, day, flag1,rate,temp,i,A,B;
// Bit assignment of flag1
// mask byte effect
// 0x20 installation test on/off(0)
// 0x40 compare time enable bit(1)
// 0x10 blink disable (1)
// 0x01 button pressed (1)
time() // update clock every 1 second
{
sec++;
if ( sec >= 60)
{
sec = 0;
min++;
if ( min >= 60)
{
min = 0;
hour++;
if ( hour >= 24)
{
hour = 0;
day++;
if ( day >= 8)
day = 1;
}
}
}
}
// convert() function provides direct entering decimal value of preset
// time in 64 bytes eeprom data memory
// say, 19 00 04 ; when reach 19:00 turns RB2 on
// as seen by Nigel's PigPro16 eeprom window, 19 means 19h or 25d
// convert will substract 25 with 6 giving 19.
// similarly but substract with 12 if > 19, e.g., 20h or 32d convert
// function will give 32d - 12d = 20.
convert() // entry : index pointer i
// exit: A,B
{
A = read_eeprom(i);
if ((A > 0x09) && (A < 0x20))
A = A - 6; // convert 10h-19h to 10d-19d
if ( A> 0x19 )
A = A - 12; // convert 20h-23h to 20d-23d
B = read_eeprom(i+1);
if ((B > 0x09) && (B < 0x20))
B = B - 6;
if ((B >= 0x20) && (B < 0x30))
B= B - 12;
if ((B >= 0x30) && (B < 0x40))
B= B - 18;
if ((B >= 0x40) && (B < 0x50))
B= B - 24;
if ((B >= 0x50) && (B < 0x60))
B= B - 30;
}
scan_PGM() // scan program saved in user eeprom
{
if((flag1 & 0x40) != 0) // allow entering only after S1 has been pressed
{
i = 0;
while( read_eeprom(i) != 0xff) // if not EOF (0xff) do
{
convert();
if (hour == A && min == B)
port_B = ~read_eeprom(i+2)|0x03; // fire output
i = i+3; // next address
}
}
}
setTime()
{
if ((flag1 & 0x01) != 0) //input(KEY)==0)
{
i = 62; // put index for reading eeprom data from 62 and 63
convert(); // converts hex to dec
hour = A; // read time to set saved in eeprom 213EH for set hour
min = B; // and address 213FH for set minute
sec = 0;
// make port B all bit high
port_B = 0xFF;
flag1 |= 0x40; // enable compare time
flag1 &= ~0x20; // reenable test on off
flag1 &= ~0x01; // clear key press bit
rate = 3;
}
}
blink() // turn LED on 100 ms
{
output_low(LED);
delay_ms(100);
output_high(LED);
}
fireLED()
{
temp++;
if ( temp == rate)
{
blink();
temp = 0;
}
}
chkKEY()
{
if(input(KEY)==0)
{flag1 |= 0x01; // set bit 0 telling key been pressed
flag1 |= 0x10; // disable firing LED
// output_high(LAMP); // turn on lamp when press button
}
}
main()
{
setup_counters(RTCC_INTERNAL,RTCC_DIV_32); // [32768/4]/32 = 256Hz
/* 256Hz clock will be counted by Timer, when it rolls from FF to 00
T0IF will then be set, in other word, one second has elapsed */
output_low(LED);
flag1 = 0;
rate = 1;
temp = 0;
tmr0 = 0;
day = 1;// Set to the required day.(Mon = 1 ,Sun =7)
hour = 18;
min = 0;
sec = 0;
while(1)
{
while(!bit_test(intcon,2))
chkKEY(); // check key S1 while T0IF = 0
bit_clear(intcon,2);
// the following tasks executed every 1 second
output_high(PIN_B7); // use RB7 for measuring tasks execution
time();
if (day <= 5) scan_PGM();
fireLED();
setTime();
output_low(PIN_B7);
}
} |
Partager