Ricardo_Electropepper
Member level 3
- Joined
- Mar 18, 2014
- Messages
- 59
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 8
- Activity points
- 407
Hello guys,
Im using a pic 12f1822 set up for the internal clock at 1MHZ.
So i used this delay code generator, and inserted into my C code, my problem is that i can see on the osciloscope that the clock is kind of drifting in time, i tried changing values around but im now stuck.
Here goes the code :
Im using a pic 12f1822 set up for the internal clock at 1MHZ.
So i used this delay code generator, and inserted into my C code, my problem is that i can see on the osciloscope that the clock is kind of drifting in time, i tried changing values around but im now stuck.
Here goes the code :
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 #include <pic12f1822.h> /* Setup chip configuration */ __code int __at(_CONFIG1) __CONFIG = _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF; void setup(void); void delay_ms(int milis); unsigned char minute = 60; void main(void) { setup(); while(1) { delay_ms(1000); LATA |= (1<<2); delay_ms(1000); LATA &= ~(1<<2); } } void setup(void) { OSCCON = 0b01011000; LATA = 0; TRISA = 0x00; PORTA = 0x00; // Reserv 2 bytes for assembly delay routine __asm cblock 0x20 d1 endc __endasm; } void delay_ms(int milis) { while (milis--) { // 1 ms at 1MHZ clock __asm Delay: ;244 cycles movlw 0x51 movwf d1 Delay_0: decfsz d1, f goto Delay_0 ;2 cycles goto $+1 ;4 cycles (including call) __endasm; } }