Hi
Have this simpel setup. , see attached schematic.
The problem is that it will only Work, when i put my finger in near of the xtal ( not touch )
When it then runs, it runs to slow.
ex 60 times at 1 sec each gives 1 minut, but it takes 77 seconds to do it in real seconds.
here is the code
i use a 16F1509 microchip.
Have this simpel setup. , see attached schematic.
The problem is that it will only Work, when i put my finger in near of the xtal ( not touch )
When it then runs, it runs to slow.
ex 60 times at 1 sec each gives 1 minut, but it takes 77 seconds to do it in real seconds.
here is the code
i use a 16F1509 microchip.
Code:
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
#include <string.h>
#pragma config FOSC = LP // Oscillator Selection Bits (XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover Mode (Internal/External Switchover Mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
#define _XTAL_FREQ 16000000
#define FOSC 16000000L
#define set_hour RB4 //Buttons
#define set_minut RC2
#define set_week RC1
#define set_time RC3
bit sec;
int secund;
char test[10];
static void interrupt isr(void) // Here is interrupt function - the name is unimportant.
{
if(TMR1IF)
TMR1L=0x00;
TMR1H=0x80;
TMR1IF=0;
sec=1;
RA2=!RA2;
}
void setup (void)
{
IRCF0=1; //16 mhz
IRCF1=1;
IRCF2=1;
IRCF3=1;
SCS0=0; // osc til 1 sec
SCS1=0;
TRISA=0; //set all port out
TRISA2=0; // set port 2 ind
TRISA4=1; // set port 4 ind.
TRISA5=1; // set port 5 ind.
TRISB4=1; // port B 4 in
TRISB5=1; // port b 5 in
TRISB6=0; // b6 ud
TRISB7=1; // port b7 in
TRISC0=0;
TRISC1=1;
TRISC2=1;
TRISC3=1;
TRISC4=0;
TRISC5=0;
TRISC6=0;
TRISC7=0;
TMR1CS0=0;
TMR1CS1=1;
T1OSCEN=1;
GIE = 0; // Global interrupt disable just in case
//ANSELA = 0b00000001; // Set PORT AN0 to analog input AN1 to AN7 digital I/O
ANSELA=0; // set alle digital.
ANSELB=0;
ANSELC=0;//turn off all analog functions
lcd_init();
T1CKPS1=0;
T1CKPS0=0;
}
void main (void)
{
setup(); //do the setup
lcd_clear();
lcd_goto(0x00);
lcd_puts("1234567890abcdefghij");
lcd_goto(0x40);
lcd_puts("abcdefghij1234567890");
__delay_ms(1000);
lcd_clear();
TMR1L=0x00;
TMR1H=0x80;
TMR1ON=1; // turn on timer1
sec=0;
PEIE=1;
TMR1IE=1;
TMR1GE=1;
GIE=1;
lcd_goto(0x00);
while (1)
{
if (sec==1)
{
secund++;
//if (secund==60) secund =0
itoa(test, secund, 10);
lcd_goto(0x01);
lcd_puts(test);//*/
sec=0;
}
}
}
Attachments
-
14.6 KB Views: 24

