/* This is a clock example program for the XMEGA .
Description:
simple CLOCK starting from 00:00:00
PLL and internal 32MHz RC osc are activated */
/* Include I/O definition file */
#include <ioavr.h>
#include <intrinsics.h>
#include "display.h"
///function for display on 7segments
/// void display(unsigned char seg_select,unsigned char seg_data);
//7seg codes
unsigned char __flash seg[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6 f};
//second variable(initial value = 0)
unsigned int sec=0;
//minute variable(initial value = 0)
unsigned int min=0;
//hour variable(initial value = 0)
unsigned int hour=0;
unsigned char select;
//--------------------------------------------------------------------------------------------------------------
void main()
{
//variable for select 7segments
// port init
//PORTE & PORTF = OUT
PORTE_DIR=0XFF;
PORTF_DIR=0X7E;
//initialize timer
TCC0_CTRLA=0X05; //Div64
TCC0_INTCTRLA=1; //Timer overflow interrupt enable
TCC0_PER=31249; //for 1sec((64/2MHZ)*(31249+1))
//interrupt enable
PMIC_CTRL=0X01; //set low level interrupt enable
asm("sei"); //set global interrupt enable flag
while(1) // program main loop
{
select=2;
display(select,seg[(sec%10)]); //turn on 1 7segment and display 1section of second
select <<= 1;
__delay_cycles(2000);
display(select,seg[(sec/10)]); //turn on 2 7segment and display 2section of second
select <<= 1;
__delay_cycles(2000);
display(select,seg[(min%10)]); //turn on 3 7segment and display 1section of minute
select <<= 1;
__delay_cycles(2000);
display(select,seg[(min/10)]); //turn on 4 7segment and display 2section of minute
select <<= 1;
__delay_cycles(2000);
display(select,seg[(hour%10)]); //turn on 5 7segment and display 1section of hour
select <<= 1;
__delay_cycles(2000);
display(select,seg[(hour/10)]); //turn on 6 7segment and display 2section of hour
__delay_cycles(2000);
}
}
//-------------------------------------------------------------------------------------------------------------
// void display(unsigned char seg_select,unsigned char seg_data)
// {
// PORTF_OUT=0X00; // Blank all 7segments
// PORTE_OUT = seg_data;
//if(seg_select==8 || seg_select==32) //turn on 7segments point
// PORTE_OUTSET=128;
// PORTF_OUT = seg_select;
// }
//------------------------------------------------------------------------------------------------------------
//interrupt timer C0 function
#pragma vector= TCC0_OVF_vect
__interrupt void timerc0(void)
{
sec++;
if(sec == 60)
{
min++;
sec=0;
if(min == 60)
{
hour++;
min=0;
if(hour ==24)
hour=0;
}
}
}
[/LEFT][/RIGHT][/LEFT][/LEFT][/LEFT]