سلام ، من یه برنامه ساعت نوشتم با MPLAB X IDE وکامپایلر XC8 با pic18f2550 و کریستال ساعت رو به دو پایه T1CKOوT1CKI وصل کردم ولی درست کار نمیکنه!ممنون میشم بگید چرا دقیق کار نمیکنه.
اینم برنامش
اینم برنامش
#define _XTAL_FREQ 8000000
#include "config.h"
#include "lcd.h"
#include <xc.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
volatile unsigned char time[20];
volatile unsigned char hour;
volatile unsigned char minute;
volatile unsigned char second;
void main(void) {
TRISCbits.TRISC7 = 0;
TRISCbits.TRISC6 = 0;
TRISCbits.TRISC2 = 0;
TRISB = 0x00;
TMR1H = 0x80;
TMR1L = 0x00;
T1CON = 0x0F;
T1CONbits.TMR1CS = 1;
IPR1bits.TMR1IP = 1;
PIR1bits.TMR1IF = 0;
PIE1bits.TMR1IE = 1;
T1CONbits.T1OSCEN = 1;
T1CONbits.NOT_T1SYNC = 1;
__delay_ms(10);
lcd_init();
__delay_ms(10);
T1CONbits.TMR1ON = 1;
RCONbits.IPEN = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
while(1)
{
lcd_cmd(0x80);
sprintf(time, "%02d:%02d:%02d",hour, minute, second);
lcd_msg(time);
__delay_ms(95);
}
}
void interrupt timer1_ISR() {
if (PIR1bits.TMR1IF == 1) {
second+=1 ;
if(second>59){
second=0;
minute+=1;
if(minute>59){
minute=0;
hour+=1;
if(hour>23){
hour=0;
}
}
}
PIR1bits.TMR1IF = 0;
TMR1H = 0x80;
TMR1L = 0x00;
}
}
#include "config.h"
#include "lcd.h"
#include <xc.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
volatile unsigned char time[20];
volatile unsigned char hour;
volatile unsigned char minute;
volatile unsigned char second;
void main(void) {
TRISCbits.TRISC7 = 0;
TRISCbits.TRISC6 = 0;
TRISCbits.TRISC2 = 0;
TRISB = 0x00;
TMR1H = 0x80;
TMR1L = 0x00;
T1CON = 0x0F;
T1CONbits.TMR1CS = 1;
IPR1bits.TMR1IP = 1;
PIR1bits.TMR1IF = 0;
PIE1bits.TMR1IE = 1;
T1CONbits.T1OSCEN = 1;
T1CONbits.NOT_T1SYNC = 1;
__delay_ms(10);
lcd_init();
__delay_ms(10);
T1CONbits.TMR1ON = 1;
RCONbits.IPEN = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
while(1)
{
lcd_cmd(0x80);
sprintf(time, "%02d:%02d:%02d",hour, minute, second);
lcd_msg(time);
__delay_ms(95);
}
}
void interrupt timer1_ISR() {
if (PIR1bits.TMR1IF == 1) {
second+=1 ;
if(second>59){
second=0;
minute+=1;
if(minute>59){
minute=0;
hour+=1;
if(hour>23){
hour=0;
}
}
}
PIR1bits.TMR1IF = 0;
TMR1H = 0x80;
TMR1L = 0x00;
}
}