//**************************************
//**************************************
// Clock 16Mhz
// Version 1.0 Janvier 2002
// Sylvain Bissonnette
//**************************************
//**************************************
// I N C L U D E
//**************************************
#i nclude
#i nclude
//**************************************
// D E F I N E
//**************************************
#define TRUE 0x01
#define FALSE 0x00
#define ANALOG 0x01
#define DIGITAL 0x02
//**************************************
// I N T E R R U P T H A N D L E R
//**************************************
#pragma interrupt_handler Crossing_interrupt:2
#pragma interrupt_handler IR_interrupt:4
#pragma interrupt_handler Degre_interrupt:5
#pragma interrupt_handler Ticker_interrupt:7
//**************************************
// P R O T O T Y P E
//**************************************
//**************************************
// M A I N
//**************************************
void main()
{
WDTCR = 0x0e; // Enable WatchDog at 0.97 sec
PORTD = 0x0d; // Pull up on PD2&D3 & Led White ON
DDRD = 0x03; // PD0-O PD1-O PD2-I PD3-I PD4-I PD5-I PD6-I PD7-I
//INT 0
MCUCR = 0x02; // Int0 generate int on falling eadge
GIMSK = 0x40; // Int0 enable
//Timer0
TCCR0 = 0x05; // Timer0 / 1024
//Timer1
TCCR1B = 0x42; // Timer1 / 8 & Input Capture on Rising eadge
TIMSK = 0x4a; // int enable on Timer1 Compare Match
// int enable on Timer 1 Input Capture
// int enable on Timer0 Overflow
PORTB = 0x00;
DDRB = 0xff; // PB0-7 as output
Hrs = 0;
Min = 0;
Sec = 0;
ClockStyle = ANALOG;
SEI();
while(1)
{
asm("WDR");
for (i=0;i<200;i++);
if ((LatchedIrData == 0xbb) || (LatchedIrData == 0x92)) Time(TRUE);
if ((LatchedIrData == 0xb3) || (LatchedIrData == 0xb0)) ClockStyle = DIGITAL;
if ((LatchedIrData == 0xb4) || (LatchedIrData == 0xb1)) ClockStyle = ANALOG;
Description: This routine is called whenever a rising edge (beginning
of valid IR signal) is received.
- The data codes are sent using pulse coding.
- Each packet has 12 bits and a header.
- The basic time period T = 550us.
- The header length = 4T (2.2ms)
- 0 = pulse with length T followed by space of length T.
- 1 = pulse with length 2T followed by space of length T.
- The last 5 bits represent the Addess.
- The first 7 bits represent the command.
- A packet is transmitted every 25ms while a button is down.
Input: none
Output: Global variable LatchedIrData
Misc: Sony VCR protocol
**********************************************************/
void IR_interrupt(void)
{
static unsigned int LastCapture;
unsigned int PulseWidth;
static unsigned int IrPulseCount;
static unsigned int IrData;