Revision: 1413
Author: robhamerling
Date: Sat Oct 24 12:01:57 2009
Log: RTC library: added prefix _rtc_ to names of 'internal' constants and  
variables.
3 new samples for RTC library with 16f886 for 20 MHz resonator and for
internal oscillator at 4 MHz and 125KHz.


http://code.google.com/p/jallib/source/detail?r=1413

Added:
  /trunk/sample/16f886_rtc_lcd_125khz.jal
  /trunk/sample/16f886_rtc_lcd_20mhz.jal
  /trunk/sample/16f886_rtc_lcd_4mhz.jal
Modified:
  /trunk/CHANGELOG
  /trunk/TORELEASE
  /trunk/include/jal/rtc_isr_tmr0.jal

=======================================
--- /dev/null
+++ /trunk/sample/16f886_rtc_lcd_125khz.jal     Sat Oct 24 12:01:57 2009
@@ -0,0 +1,103 @@
+-- Title: Sample program to show usage of rtc_isr_tmr0
+-- Author: Eur van Andel, Copyright (c) 2008, all rights reserved.
+-- Adapted-by: Albert Faber, Rob Hamerling
+-- Compiler: 2.4l
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license  
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Sources:  http://www.romanblack.com/one_sec.htm,  
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
+--
+-- Description: This program shows how to get Real Time in a PIC
+--
+-- Notes: there is no way to set the time in this program, other than  
before compiling
+-- for more options, including automatic initialisation and timesetting,  
see sample_rtc_timeset.jal
+--
+-- ------------------- SELECT PIC ----------------------------
+include 16f886
+
+pragma target clock        125_000          -- oscillator speed
+pragma target OSC       INTOSC_NOCLKOUT     -- internal oscillator
+pragma target WDT       disabled            -- no watchdog, please
+pragma target LVP       disabled            -- no low voltage programming
+
+enable_digital_io()                         -- no analog pins used in this  
sample
+
+OPTION_REG_T0CS = 0                         -- Timer0 on instruction cycle  
clock
+OPTION_REG_PSA  = 1                         -- Timer0 assigned to WDT
+OPTION_REG_PS   = 0                         -- Timer0 prescale 1:1
+
+OSCCON_IRCF = 0b001                         -- internal oscillator: 4 MHz
+OSCCON_SCS  = 0                             -- config bits determine clock  
source
+
+-- ------------------------ LIBRARIES ------------------------
+
+include rtc_isr_tmr0
+
+var byte minutes  = 14                      -- seconds defined in RTC lib
+var byte hours    = 20                      -- arbitrary time
+
+var byte date     = 24
+var byte month    = 10
+var word year     = 2009                    -- today
+
+include calendar                            -- 60/24/27..31/12 range limits
+
+const byte  LCD_ROWS = 4
+const byte  LCD_CHARS = 20
+alias lcd_rs           is pin_c4            -- lcd command/data select.
+alias lcd_en           is pin_c5            -- lcd data trigger
+alias lcd_d4           is pin_b0
+alias lcd_d5           is pin_b1            -- lcd data nibble
+alias lcd_d6           is pin_b2
+alias lcd_d7           is pin_b3
+portB_low_direction    = all_output
+pin_C4_direction       = output
+pin_C5_direction       = output
+include lcd_hd44780_4                       -- lcd library with 4 data  
lines
+lcd_init()
+
+include print                               -- nice formatted output
+include format                              -- more nice formatting
+
+-- -------------------------- START PROGRAM -----------------
+
+INTCON_TMR0IE = on                          -- if your PIC freezes, move  
these lines
+INTCON_GIE = on                             -- to see if the ISR causes  
trouble
+
+const byte str1[] = "Time RTC sample "
+const byte str2[] = "Fosc "
+const byte str3[] = " Hz"
+
+lcd_clear_screen()
+lcd_cursor_position(0,0)                    -- line 1
+print_string(lcd, str1)
+lcd_cursor_position(1,0)                    -- line 2
+print_string(lcd, str2)
+print_dword_dec(lcd,target_clock)
+print_string(lcd, str3)
+
+forever loop
+   lcd_cursor_position(2,0)                 -- line 3
+   print_byte_dec(lcd, date)
+   lcd = "-"
+   print_byte_dec(lcd, month)
+   lcd = "-"
+   print_word_dec(lcd, year)
+   lcd = " "
+   if seconds > 59 then                     -- once every minute
+      calendar()
+   end if
+   format_time_hms(lcd, hours, minutes, seconds)
+
+   lcd_cursor_position(3,0)                 -- line 4
+   if ((seconds & 0b0000_0001) == 0) then
+      lcd = "*"                             -- on
+   else
+      lcd = " "                             -- off
+   end if
+end loop
+
+
+
+
=======================================
--- /dev/null
+++ /trunk/sample/16f886_rtc_lcd_20mhz.jal      Sat Oct 24 12:01:57 2009
@@ -0,0 +1,102 @@
+-- Title: Sample program to show usage of rtc_isr_tmr0
+-- Author: Eur van Andel, Copyright (c) 2008, all rights reserved.
+-- Adapted-by: Albert Faber, Rob Hamerling
+-- Compiler: >=2.4l
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license  
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Sources:  http://www.romanblack.com/one_sec.htm,  
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
+--
+-- Description: This program shows how to get Real Time in a PIC
+--
+-- Notes: there is no way to set the time in this program, other than  
before compiling
+-- for more options, including automatic initialisation and timesetting,  
see sample_rtc_timeset.jal
+--
+-- ------------------- SELECT PIC ----------------------------
+include 16f886
+
+pragma target clock     20_000_000          -- oscillator speed
+pragma target OSC       HS                  -- resonator
+pragma target WDT       disabled            -- no watchdog, please
+pragma target LVP       disabled            -- no low voltage programming
+
+enable_digital_io()                         -- no analog pins used in this  
sample
+
+OPTION_REG_T0CS = 0                         -- Timer0 on instruction cycle  
clock
+OPTION_REG_PSA  = 1                         -- Timer0 assigned to WDT
+OPTION_REG_PS   = 0                         -- Timer0 prescale 1:1
+
+
+-- ------------------------ LIBRARIES ------------------------
+
+include rtc_isr_tmr0
+
+var byte minutes  = 18                      -- seconds defined RTC lib
+var byte hours    = 20                      -- arbitrary time
+
+var byte date     = 24
+var byte month    = 10
+var word year     = 2009                    -- today
+
+include calendar                            -- 60/24/27..31/12 range limits
+include delay
+
+const byte  LCD_ROWS = 4
+const byte  LCD_CHARS = 20
+alias lcd_rs           is pin_c4            -- lcd command/data select.
+alias lcd_en           is pin_c5            -- lcd data trigger
+alias lcd_d4           is pin_b0
+alias lcd_d5           is pin_b1            -- lcd data nibble
+alias lcd_d6           is pin_b2
+alias lcd_d7           is pin_b3
+portB_low_direction    = all_output
+pin_C4_direction       = output
+pin_C5_direction       = output
+include lcd_hd44780_4                       -- lcd library with 4 data  
lines
+lcd_init()
+
+include print                               -- nice formatted output
+include format                              -- more nice formatting
+
+-- -------------------------- START PROGRAM -----------------
+
+INTCON_TMR0IE = on                          -- if your PIC freezes, move  
these lines
+INTCON_GIE = on                             -- to see if the ISR causes  
trouble
+
+const byte str1[] = "Time RTC sample "
+const byte str2[] = "Fosc "
+const byte str3[] = " Hz"
+
+lcd_clear_screen()
+lcd_cursor_position(0,0)                    -- line 1
+print_string(lcd, str1)
+lcd_cursor_position(1,0)                    -- line 2
+print_string(lcd, str2)
+print_dword_dec(lcd,target_clock)
+print_string(lcd, str3)
+
+forever loop
+   lcd_cursor_position(2,0)                 -- line 3
+   print_byte_dec(lcd, date)
+   lcd = "-"
+   print_byte_dec(lcd, month)
+   lcd = "-"
+   print_word_dec(lcd, year)
+   lcd = " "
+   if seconds > 59 then                     -- once every minute
+      calendar()
+   end if
+   format_time_hms(lcd, hours, minutes, seconds)
+
+   lcd_cursor_position(3,0)                 -- line 4
+   if ((seconds & 0b0000_0001) == 0) then
+      lcd = "*"                             -- on
+   else
+      lcd = " "                             -- off
+   end if
+end loop
+
+
+
+
=======================================
--- /dev/null
+++ /trunk/sample/16f886_rtc_lcd_4mhz.jal       Sat Oct 24 12:01:57 2009
@@ -0,0 +1,103 @@
+-- Title: Sample program to show usage of rtc_isr_tmr0
+-- Author: Eur van Andel, Copyright (c) 2008, all rights reserved.
+-- Adapted-by: Albert Faber, Rob Hamerling
+-- Compiler: 2.4l
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license  
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Sources:  http://www.romanblack.com/one_sec.htm,  
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
+--
+-- Description: This program shows how to get Real Time in a PIC
+--
+-- Notes: there is no way to set the time in this program, other than  
before compiling
+-- for more options, including automatic initialisation and timesetting,  
see sample_rtc_timeset.jal
+--
+-- ------------------- SELECT PIC ----------------------------
+include 16f886
+
+pragma target clock      4_000_000          -- oscillator speed
+pragma target OSC       INTOSC_NOCLKOUT     -- internal oscillator
+pragma target WDT       disabled            -- no watchdog, please
+pragma target LVP       disabled            -- no low voltage programming
+
+enable_digital_io()                         -- no analog pins used in this  
sample
+
+OPTION_REG_T0CS = 0                         -- Timer0 on instruction cycle  
clock
+OPTION_REG_PSA  = 1                         -- Timer0 assigned to WDT
+OPTION_REG_PS   = 0                         -- Timer0 prescale 1:1
+
+OSCCON_IRCF = 0b110                         -- internal oscillator: 4 MHz
+OSCCON_SCS  = 0                             -- config bits determine clock  
source
+
+-- ------------------------ LIBRARIES ------------------------
+
+include rtc_isr_tmr0
+
+var byte minutes  = 14                      -- seconds defined in RTC lib
+var byte hours    = 20                      -- arbitrary time
+
+var byte date     = 24
+var byte month    = 10
+var word year     = 2009                    -- today
+
+include calendar                            -- 60/24/27..31/12 range limits
+
+const byte  LCD_ROWS = 4
+const byte  LCD_CHARS = 20
+alias lcd_rs           is pin_c4            -- lcd command/data select.
+alias lcd_en           is pin_c5            -- lcd data trigger
+alias lcd_d4           is pin_b0
+alias lcd_d5           is pin_b1            -- lcd data nibble
+alias lcd_d6           is pin_b2
+alias lcd_d7           is pin_b3
+portB_low_direction    = all_output
+pin_C4_direction       = output
+pin_C5_direction       = output
+include lcd_hd44780_4                       -- lcd library with 4 data  
lines
+lcd_init()
+
+include print                               -- nice formatted output
+include format                              -- more nice formatting
+
+-- -------------------------- START PROGRAM -----------------
+
+INTCON_TMR0IE = on                          -- if your PIC freezes, move  
these lines
+INTCON_GIE = on                             -- to see if the ISR causes  
trouble
+
+const byte str1[] = "Time RTC sample "
+const byte str2[] = "Fosc "
+const byte str3[] = " Hz"
+
+lcd_clear_screen()
+lcd_cursor_position(0,0)                    -- line 1
+print_string(lcd, str1)
+lcd_cursor_position(1,0)                    -- line 2
+print_string(lcd, str2)
+print_dword_dec(lcd,target_clock)
+print_string(lcd, str3)
+
+forever loop
+   lcd_cursor_position(2,0)                 -- line 3
+   print_byte_dec(lcd, date)
+   lcd = "-"
+   print_byte_dec(lcd, month)
+   lcd = "-"
+   print_word_dec(lcd, year)
+   lcd = " "
+   if seconds > 59 then                     -- once every minute
+      calendar()
+   end if
+   format_time_hms(lcd, hours, minutes, seconds)
+
+   lcd_cursor_position(3,0)                 -- line 4
+   if ((seconds & 0b0000_0001) == 0) then
+      lcd = "*"                             -- on
+   else
+      lcd = " "                             -- off
+   end if
+end loop
+
+
+
+
=======================================
--- /trunk/CHANGELOG    Sat Oct 24 05:57:20 2009
+++ /trunk/CHANGELOG    Sat Oct 24 12:01:57 2009
@@ -37,6 +37,7 @@
   - eeprom samples for 18Fs
   - added sample files for PIC16f723
   - added auto start USB bootloader
+ - 3 samples of use of RTC library with 16F886 (resonator and internal  
oscillator)

  compiler:
   -
=======================================
--- /trunk/TORELEASE    Sun Sep 20 15:19:39 2009
+++ /trunk/TORELEASE    Sat Oct 24 12:01:57 2009
@@ -471,6 +471,9 @@
  sample/16f886_blink.jal
  sample/16f886_pwm_adc_freq.jal
  sample/16f886_pwm_adc_res.jal
+sample/16f886_rtc_lcd_125khz.jal
+sample/16f886_rtc_lcd_20mhz.jal
+sample/16f886_rtc_lcd_4mhz.jal
  sample/16f887_blink.jal
  sample/16f887_lcd_hd44780_4_1.jal
  sample/16f887_lcd_hd44780_4_4.jal
=======================================
--- /trunk/include/jal/rtc_isr_tmr0.jal Sat Oct 24 10:49:37 2009
+++ /trunk/include/jal/rtc_isr_tmr0.jal Sat Oct 24 12:01:57 2009
@@ -6,14 +6,14 @@
  -- This file is part of jallib (http://jallib.googlecode.com)
  -- Released under the ZLIB license  
(http://www.opensource.org/licenses/zlib-license.html)
  --
--- Sources:  http://www.romanblack.com/one_sec.htm
---           http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
+-- Sources: http://www.romanblack.com/one_sec.htm
+--          http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
  --
  -- Description: This Interrupt Service Routine updates the variable seconds
--- about once per second. -- The precision is 0.2 ppm, the accuracy depends
+-- about once per second. The precision is 0.2 ppm, the accuracy depends
  -- on the Xtal used.
--- --
--- Notes : This is the Bresenham Line Algorithm, invented at IBM in 1962,
+--
+-- Notes: This is the Bresenham Line Algorithm, invented at IBM in 1962,
  -- which gets an accurate end result by summing the small errors resulting  
of
  -- taking discrete steps and correcting when the error gets too large. This
  -- means that individual second lengths may show some jitter, but that  
long-term
@@ -28,54 +28,57 @@
  -- this keeps clock count accurate, although interrupts happen every 256  
clock
  -- counts the ISR subtracts 1 from the mid byte. It first checks
  -- the mid byte for zero and borrows a bit from bres_hi if needed.
---
--- Required PIC settings: OPTION_REG_PSA = 0
+-- --
+-- Required PIC settings: OPTION_REG_PSA = 1
  --                        OPTION_REG_PS = 0
+--                        OPTION_REG_T0CS = 0   -- Timer0 on instruction  
cycle clock
  --

-
  var volatile byte seconds               -- global variable updated by ISR

-const  _cycles_per_second = (target_clock / 4)
-
-const  byte  hi  = _cycles_per_second / 65536
-const  byte  mid = _cycles_per_second % 65536 / 256
-const  byte  lo  = _cycles_per_second % 256
-
-var volatile byte bres_hi  = hi         -- \
-var volatile byte bres_mid = mid        --  > init 3-byte counter
-var volatile byte bres_lo  = lo         -- /
+const  _rtc_cycles_per_second = (target_clock / 4)
+
+const  byte  _rtc_hi  = _rtc_cycles_per_second / 65536
+const  byte  _rtc_mid = _rtc_cycles_per_second % 65536 / 256
+const  byte  _rtc_lo  = _rtc_cycles_per_second % 256
+
+var volatile byte _rtc_bres_hi  = _rtc_hi      -- \
+var volatile byte _rtc_bres_mid = _rtc_mid     --  > init 3-byte counter
+var volatile byte _rtc_bres_lo  = _rtc_lo      -- /

  procedure RTC() is
+
     pragma interrupt
+
     assembler                            -- fast ISR: so assembler
        local int_exit                    -- labels for jumping

-      bcf   INTCON_TMR0IF               -- clear the timer 0 interrupt flag
-      movf  bres_mid,f                  -- mid == 0 ?
-      btfsc STATUS_Z                    -- not zero?
-      decf  bres_hi, f                  -- zero, borrow one from high byte
-      decfsz bres_mid, f                 -- this is the count of the  
interrupts
-      goto  int_exit                    -- mid byte is not zero, so exit
-      movf  bres_hi, f                  -- mid == 0, might hi == 0 too ?
-      btfss STATUS_Z
-      goto  int_exit                    -- high byte not zero, so exit
+      bcf    INTCON_TMR0IF              -- clear the timer 0 interrupt flag
+      movf   _rtc_bres_mid,f                 -- mid == 0 ?
+      btfsc  STATUS_Z                   -- not zero?
+      decf   _rtc_bres_hi, f            -- zero, borrow one from high byte
+      decfsz _rtc_bres_mid, f           -- this is the count of the  
interrupts
+      goto   int_exit                   -- mid byte is not zero, so exit
+      movf   _rtc_bres_hi, f            -- mid == 0, might hi == 0 too ?
+      btfss  STATUS_Z
+      goto   int_exit                   -- high byte not zero, so exit
                                          -- high byte zero, mid also zero
                                          -- we need to load the one-second  
timer

-      movlw hi                          -- add  cycles_per_second to  
hi-mid-lo
-      movwf bres_hi                     -- hi & mid are both zero
-      movlw mid
-      movwf bres_mid
-      movlw lo                          -- lo is not zero, and must be  
added
-      addwf bres_lo, f                  -- bres_lo can overflow
+      movlw _rtc_hi                     -- add  cycles_per_second to  
hi-mid-lo
+      movwf _rtc_bres_hi                -- hi & mid are both zero
+      movlw _rtc_mid
+      movwf _rtc_bres_mid
+      movlw _rtc_lo                     -- lo is not zero, and must be  
added
+      addwf _rtc_bres_lo, f             -- bres_lo can overflow
        btfsc STATUS_C                    -- does it?
-      incf  bres_mid, f                 -- yes, but mid was 0x4B, so will  
not overflow
+      incf  _rtc_bres_mid, f            -- yes, but mid was 0x4B, so will  
not overflow
        incf  seconds, f                  -- main routine should check  
seconds
                                          -- and call calendar when seconds  
> 59
                                          -- and take care of minutes, etc.
        int_exit:
     end assembler
+
  end procedure                           -- end of ISR



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to