#include<p18cxxx.h>
#include<delays.h>
#include<xlcd.h>
#pragma config OSC=HS
#pragma config WDT=OFF
#pragma config LVP=OFF
#pragma config BOR=OFF
#pragma config MCLRE=OFF

void MyHighInt(void);

#pragma interrupt MyHighInt    //Это высокоприоритетное прерывание
#pragma code high_vector=0x08  //Это вектор по адресу 0х08
void high_vector(void){
    _asm GOTO MyHighInt _endasm
}
//----------------------Память данных------------------------------
#pragma udata access IntMyData
near short long time;
#pragma udata
char timeString[12];
//---------------------Функции-------------------------------------
#pragma code
///////////////////////////////////////////////
void DelayFor18TCY(void)
{
    Delay10TCYx(2);
}
void DelayPORXLCD(void)
{
    Delay1KTCYx(15);
}
void DelayXLCD(void)
{
    Delay1KTCYx(5);
}
///////////////////////////////////////////////////////////////////
void getTimeString(char mode)
{
    char ptr=0;
    char hours=time/3600;
    char amPM='A';
    char minutes=(time%3600)/60;
    char seconds=(time%3600)%60;
    if(mode)
    {
        if(hours==12)
        {
            hours-=12;
            amPM='P';
        }
        if(hours==0)
            hours=12;
    }
    if((hours/10)==0){
        timeString[ptr++]=' ';
    }
    else{
        timeString[ptr++]=hours/10|0x30;
    }
    timeString[ptr++]=hours%10|0x30;
    
    timeString[ptr++]=':';
    timeString[ptr++]=minutes/10|0x30;
    timeString[ptr++]=minutes%10|0x30;
    
    timeString[ptr++]=':';
    timeString[ptr++]=seconds/10|0x30;
    timeString[ptr++]=seconds%10|0x30;
    if(mode)
    {
        timeString[ptr++]=' ';
        timeString[ptr++]=amPM;
        timeString[ptr++]='M';
    }
    timeString[ptr]=0;
}
void DoTime(void)
{
    TMR1H=0x80;
    PIR1bits.TMR1IF=0;
    time++;
    if(time==86400){
        time=0;
    }
}
void MyHighInt(void){
    if(PIR1bits.TMR1IF)
    {
        DoTime();
    }
    
}

void main(void)
{
    ADCON1=0xEF;
    OpenXLCD(FOUR_BIT&LINES_5X7);
    WriteCmdXLCD(CURSOR_OFF&BLINK_OFF);
    RCONbits.IPEN=1;
    TMR1L=0x00;
    TMR1H=0x80;
    T1CON=0x01;
    IPR1bits.TMR1IP=1;
    PIE1bits.TMR1IE=1;
    INTCONbits.GIEH=1;
    while(1)
    {
        getTimeString(1);
        SetDDRamAddr(0x80);
        putsXLCD(timeString);
    }
}



НАЗАД                                                                                                                                         ДАЛЕЕ