starting bcd conversion
This commit is contained in:
		
							parent
							
								
									25ae52259d
								
							
						
					
					
						commit
						101f0b998f
					
				| 
						 | 
				
			
			@ -172,19 +172,21 @@ Returns a list with all items for which tst is true removed from lst."
 | 
			
		|||
Returns a list with all items for which tst is false removed from lst."
 | 
			
		||||
  (mapcan #'(lambda (x) (when (funcall tst x) (list x))) lst))
 | 
			
		||||
 | 
			
		||||
(defvar *rtc-port* 1)
 | 
			
		||||
 | 
			
		||||
(defun rtc-set (hr min)
 | 
			
		||||
 "(rtc-set hr min)
 | 
			
		||||
Set the time on a DS3231 RTC. Times are in BCD, so use
 | 
			
		||||
the appropriate reader macro, e.g. (rtc-set #x12 #x34)
 | 
			
		||||
for 12:34. Assumes seconds are zero."
 | 
			
		||||
  (with-i2c (str #x68)
 | 
			
		||||
  (with-i2c (str *rtc-port* #x68)
 | 
			
		||||
    (write-byte 0 str)
 | 
			
		||||
    (write-byte 0 str)
 | 
			
		||||
    (write-byte min str)
 | 
			
		||||
    (write-byte hr str)))
 | 
			
		||||
 | 
			
		||||
(defun rtc-get ()
 | 
			
		||||
  (with-i2c (str #x68)
 | 
			
		||||
  (with-i2c (str *rtc-port* #x68)
 | 
			
		||||
    (write-byte 0 str)
 | 
			
		||||
    (restart-i2c str 3)
 | 
			
		||||
    (reverse
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,26 @@
 | 
			
		|||
 User Extensions
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
// Utility functions
 | 
			
		||||
uint8_t
 | 
			
		||||
dec_to_bcd(uint8_t n)
 | 
			
		||||
{
 | 
			
		||||
	uint8_t bcd = 0;
 | 
			
		||||
	uint8_t	tens = n / 10;
 | 
			
		||||
 | 
			
		||||
	bcd = tens << 4;
 | 
			
		||||
	tens *= 10;
 | 
			
		||||
	bcd += (n - tens) & 0x0f;
 | 
			
		||||
	return bcd;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint8_t
 | 
			
		||||
bcd_to_dec(uint8_t n)
 | 
			
		||||
{
 | 
			
		||||
	return ((n>>4) * 10) + (n&0x0f);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Definitions
 | 
			
		||||
object *
 | 
			
		||||
fn_now(object *args, object *env)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in New Issue