Skip to content
This repository has been archived by the owner on Jun 1, 2018. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WJR committed Feb 25, 2012
1 parent 8da1fdb commit a0483ba
Show file tree
Hide file tree
Showing 14 changed files with 621 additions and 209 deletions.
161 changes: 0 additions & 161 deletions OpenZero/Lcd.c

This file was deleted.

184 changes: 184 additions & 0 deletions OpenZero/Lcd/Lcd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#ifndef F_CPU
#define F_CPU 1000000UL
#endif

#define TICKERSPEED 250 // msec

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

#include "Lcd.h"
#include "ZeroLcd.h"
#include "../Time/Rtc.h"

volatile uint16_t ticker = 0;

ISR(TIMER0_OVF_vect)
{
ticker++;
}

void LCD_Init(void)
{
/* Use 32 kHz crystal oscillator */
/* 1/3 Bias and 1/4 duty, SEG0:SEG24 is used as port pins, COM0:COM3 as common pins */
LCDCRB = (1<<LCDCS) | (1<<LCDMUX1) |(1<<LCDMUX0) | (1<<LCDPM2) | (1<<LCDPM1)|(1<<LCDPM0);
/* Using 16 as prescaler selection and 7 as LCD Clock Divide */
/* gives a frame rate of 49 Hz */
LCDFRR = (1<<LCDCD2) | (1<<LCDCD1);
/* Set segment drive time to 125 us and output voltage to 3.3 V*/
LCDCCR = (1<<LCDDC1) | (1<<LCDCC3) | (1<<LCDCC2) | (1<<LCDCC1);
/* Enable LCD, default waveform and interrupt enabled */
LCDCRA = (1<<LCDEN) | (1<<LCDIE);

// timer0 is being used a timer for the ticker tape
TCCR0A = (1<<CS02)|(1<<CS00); // timer clock = system clock / 1024
TIFR0 = (1<<TOV0); // clear pending interrupts
TIMSK0 = (1<<TOIE0); // enable timer0 overflow Interrupt
}

void LCD_tickertape( unsigned char *text, unsigned char len )
{
for( int chars = 0; chars<=len-LCD_MAX_CHARS; chars++ )
{
for( int i = 0; i<LCD_MAX_CHARS; i++ )
{
Lcd_Map(i,*(text+i+chars));
}

_delay_ms( TICKERSPEED );
}
}

void LCD_blinkYears( void )
{
if( ticker % 2 )
{
Lcd_Map(0,' ');
Lcd_Map(1,' ');
Lcd_Map(2,' ');
Lcd_Map(3,' ');
}
else
{
Lcd_Map(0,'0'+(rtc.year/1000)%10);
Lcd_Map(1,'0'+(rtc.year/100)%10);
Lcd_Map(2,'0'+(rtc.year/10)%10);
Lcd_Map(3,'0'+rtc.year%10);
}
}

void LCD_blinkMonths( void )
{
if( ticker % 2 )
{
Lcd_Map(0,' ');
Lcd_Map(1,' ');
}
else
{
Lcd_Map(0,'0'+(rtc.month/10)%10);
Lcd_Map(1,'0'+rtc.month%10);
}
Lcd_Map(2,'0'+(rtc.date/10)%10);
Lcd_Map(3,'0'+rtc.date%10);
}

void LCD_blinkDate( void )
{
Lcd_Map(0,'0'+(rtc.month/10)%10);
Lcd_Map(1,'0'+rtc.month%10);
if( ticker % 2 )
{
Lcd_Map(2,' ');
Lcd_Map(3,' ');
}
else
{
Lcd_Map(2,'0'+(rtc.date/10)%10);
Lcd_Map(3,'0'+rtc.date%10);
}
}

void LCD_blinkHours( void )
{
if( ticker % 2 )
{
Lcd_Map(0,' ');
Lcd_Map(1,' ');
}
else
{
Lcd_Map(0,'0'+(rtc.hour/10)%10);
Lcd_Map(1,'0'+rtc.hour%10);
}
Lcd_Map(2,'0'+(rtc.minute/10)%10);
Lcd_Map(3,'0'+rtc.minute%10);
}

void LCD_blinkMinutes( void )
{
Lcd_Map(0,'0'+(rtc.hour/10)%10);
Lcd_Map(1,'0'+rtc.hour%10);
if( ticker % 2 )
{
Lcd_Map(2,' ');
Lcd_Map(3,' ');
}
else
{
Lcd_Map(2,'0'+(rtc.minute/10)%10);
Lcd_Map(3,'0'+rtc.minute%10);
}
}

void LCD_showTime( void )
{
Lcd_Map(0,'0'+(rtc.hour/10)%10);
Lcd_Map(1,'0'+rtc.hour%10);
Lcd_Map(2,'0'+(rtc.minute/10)%10);
Lcd_Map(3,'0'+rtc.minute%10);

// or use itoa() function
}

void LCD_writeText( unsigned char *text )
{
for( int i = 0; i<LCD_MAX_CHARS; i++ )
{
Lcd_Map(i,*(text+i));
}
}

void LCD_writeNum( uint16_t num )
{
if( num>=1000 )
Lcd_Map(0,'0'+(num/1000)%10);
else
Lcd_Map(0,' ');
if(num>=100)
Lcd_Map(1,'0'+(num/100)%10);
else
Lcd_Map(1,' ');
if(num>=10)
Lcd_Map(2,'0'+(num/10)%10);
else
Lcd_Map(2,' ');
Lcd_Map(3,'0'+num%10);
}

void LCD_progressbar(uint16_t value, uint16_t max)
{
uint32_t numbars = value;
numbars *= MAXBARS;
numbars /= max;

for(uint8_t i = 0; i<MAXBARS; i++ )
{
if( i<numbars )
Lcd_Bar( i, 1 );
else
Lcd_Bar( i, 0 );
}
}
5 changes: 4 additions & 1 deletion OpenZero/Lcd.h → OpenZero/Lcd/Lcd.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#ifndef _LCD_H
#define _LCD_H

#define LCD_MAX_CHARS 4

void LCD_Init(void);
void LCD_ticker( unsigned char *text );
void LCD_blinkYears( void );
void LCD_blinkMonths( void );
void LCD_blinkDate( void );
void LCD_blinkHours( void );
void LCD_blinkMinutes( void );
void LCD_showTime( void );
void LCD_tickertape( unsigned char *text, unsigned char len );
void LCD_writeText( unsigned char *text );
void LCD_writeNum( unsigned int num );
void LCD_progressbar(uint16_t value, uint16_t max);

#endif
2 changes: 1 addition & 1 deletion OpenZero/14Segment.c → OpenZero/Lcd/Stk504.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <avr/io.h>

#include "14Segment.h"
#include "Stk504.h"

int lcdmap_stk504[] =
{
Expand Down
File renamed without changes.
Loading

0 comments on commit a0483ba

Please sign in to comment.