您当前的位置:五五电子网电子知识单片机-工控设备PIC单片机pic16f877a c语言时钟程序 正文
pic16f877a c语言时钟程序

pic16f877a c语言时钟程序

点击数:7778 次   录入时间:03-04 11:51:34   整理:http://www.55dianzi.com   PIC单片机
    TRISA = 0xff;    //    low half byte as keyscan in
    TRISE = 0x00;
    ADCON0 = 0x00;
    ADCON1 = 0x06;    //    all digital I/Os
    lcd_init();
    INTCON = 0x00;
    lcd_write_inst(0x80);    //    set lcd ddram address
    for (pStr = StrPower1;*pStr!=0;pStr++)
    {
        lcd_write_data(*pStr);
    }
    lcd_write_inst(0x0c);        //    LCD cursor off
    PIR1 = PIR2 = 0x00;
    T1CON = 0x0f;    //    T1CON:    -- T1CKPS1 T1CPS0 T1OSCEN /T1SYNC TMR1CS TMR1ON
    TMR1H = 0x80;
    TMR1L = 0x00;
    TMR1IF = 0;
    CCPR2H = 0x7f;
    CCPR2L = 0xff;
    CCP2CON = 0x0b;    //    compare mode,set ccp2if,reset tmr1
    CCP2IF = 0;
    for (cnt=5;cnt>0;cnt--)    //    test for 5sec.
    {
        lcd_write_inst(0xc0+8);    //    set LCD adress
        lcd_write_data(cnt + ’0’);
        while (CCP2IF == 0)    //    wait for timer1 overflow
        {
            restart_wdt();
        }
        //TMR1H = 0x80;
        CCP2IF = 0;
    }
    //    write current date to lcd line 2
    lcd_write_inst(0x01);        //    clear LCD display
    lcd_write_inst(0xc0+3);        //    set LCD line2
    lcd_write_data(CurrentDate.year1 + ’0’);
    lcd_write_data(CurrentDate.year2 + ’0’);
    lcd_write_data(CurrentDate.year3 + ’0’);
    lcd_write_data(CurrentDate.year4 + ’0’);
    lcd_write_data(’/’);
    lcd_write_data(CurrentDate.monthh + ’0’);
    lcd_write_data(CurrentDate.monthl + ’0’);
    lcd_write_data(’/’);
    lcd_write_data(CurrentDate.dayh + ’0’);
    lcd_write_data(CurrentDate.dayl + ’0’);
    Alarm1Enable = true;    //false;
    Alarm2Enable = true;    //false;
    INTCON = 0xc0;    //    set GIE & PEIE
    //TMR1IE = 1;        //    enable timer1 interrupt
    CCP2IE = 1;            //    enable ccp2 interrupt
    CurrentMode = mode_time;
    Alarm1Cnt = Alarm2Cnt = 0;
    T2CON = 0x07;    //    T2CON: - TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0
                    //    timer2 enable,prescaler = 16
    PR2 = PWM_period;    //    set pwm period
    CCPR1L = PWM_DC;    //    set pwm duty cycle
    CCP1CON = PWM_off;
    while(1)
    {
        restart_wdt();
        KeyOld = get_key();
        delay_ms(20);
        KeyNew = get_key();
        if (((KeyNew & 0x0f) != 0x00) & (KeyNew == KeyOld))
        {                            //    some key pressed
            if (BackLightEn == 1)    //    back light not on
            {
                BackLightEn = 0;        //    enable back-light
                BackLightTimer = 0;        //    start delay counter
            }
            else
            {
                if (KeyNew == key_0)
                    KeyNew = 0;
                else if(KeyNew == key_1)
                    KeyNew = 1;
                else if(KeyNew == key_2)

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17]  下一页


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