您当前的位置:五五电子网电子知识单片机-工控设备PIC单片机用PIC16F877的c语言写的一个时闹钟程序(转贴) 正文
用PIC16F877的c语言写的一个时闹钟程序(转贴)

用PIC16F877的c语言写的一个时闹钟程序(转贴)

点击数:7643 次   录入时间:03-04 11:39:06   整理:http://www.55dianzi.com   PIC单片机
        nop
    #endasm
    lcd_e = 0;
    return 'Y';
}

//    -------------------------------------------------------
unsigned char lcd_write_inst(unsigned char ch)
{
    while (lcd_busy)
    {    restart_wdt();    }
    lcd_rs = 0;    //    inst
    lcd_rw = 0;    //    write
    lcd_bus = ch;
    lcd_e = 1;
    #asm
        nop
        nop
        nop
    #endasm
    lcd_e = 0;
    return 'Y';
}


//    -------------------------------------------------------
unsigned char lcd_read_data()
{
    unsigned char ch;
    while (lcd_busy)
    {    restart_wdt();    }
    lcd_dir = 0xff;    //    read from lcd
    lcd_rs = 1;    //    data
    lcd_rw = 1;    //    read
    lcd_e = 1;
    #asm
        nop
        nop
        nop
    #endasm
    ch = lcd_bus;    //    read in
    lcd_e = 0;
    lcd_dir = 0x00; //  set write to lcd
    return ch;
}

//    -------------------------------------------------------
void lcd_init()
{
    unsigned char Tempch;
    lcd_addr = 0;
    delay_ms(100);
    Tempch = 0x38;    //    1-line mode,5x8 dots
    lcd_write_inst(Tempch);    //    Function set
    Tempch = 0x0f;    //    lcd on,cursor on,blink on
    lcd_write_inst(Tempch);    //    Display on/off
    Tempch = 0x06;    //    Increment mode,Entire shift off
    lcd_write_inst(Tempch);
    Tempch = 0x01;    //    clear display
    lcd_write_inst(Tempch);
    delay_ms(3);
}

//    -------------------------------------------------------
//#int_timer1
//void timer1_interrupt(void)
#int_ccp2
void ccp2_interrupt(void)
{
    //TMR1H = 0x80;
    if (CurrentTime.secondl==9)
    {
        CurrentTime.secondl=0;
        if (CurrentTime.secondh==5)
        {
            CurrentTime.secondh=0;
            if (CurrentTime.minutel==9)
            {
                CurrentTime.minutel=0;
                if (CurrentTime.minuteh==5)
                {
                    CurrentTime.minuteh=0;
                    if (CurrentTime.hourl==9)
                    {
                        CurrentTime.hourl=0;
                        CurrentTime.hourh++;
                    }
                    else if((CurrentTime.hourl==3) && (CurrentTime.hourh==2))
                    {
                        CurrentTime.hourl=0;
                        CurrentTime.hourh=0;
                        if ((((CurrentDate.dayl == 8) || (CurrentDate.dayl == 9)) && (CurrentDate.dayh == 2) && (CurrentDate.monthl == 2) && (CurrentDate.monthh == 0)) ||
                            ((CurrentDate.dayl == 0) && (CurrentDate.dayh == 3) && ((((CurrentDate.monthl == 4) || (CurrentDate.monthl == 6)
                                || (CurrentDate.monthl == 9)) && (CurrentDate.monthh == 0)) || ((CurrentDate.monthl == 1) && (CurrentDate.monthh == 1)))) ||
                            ((CurrentDate.dayl == 1) && (CurrentDate.dayh == 3)))
                        {
                            CurrentDate.dayl=1;
                            CurrentDate.dayh=0;
                            if ((CurrentDate.monthl == 2) && (CurrentDate.monthh == 1))
                            {
                                CurrentDate.monthl = 1;
                                CurrentDate.monthh = 0;
                                if (CurrentDate.year4 == 9)
                                {
                                    CurrentDate.year4 = 0;
                                    if (CurrentDate.year3 == 9)
                                    {
                                        CurrentDate.year3 = 0;
                                        if (CurrentDate.year2 == 9)
                                        {

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]  下一页


本文关键字:程序  C语言  PIC单片机单片机-工控设备 - PIC单片机