Created
February 2, 2020 11:28
-
-
Save gresan-gits/3e0852a5575c97e289c520168ade3884 to your computer and use it in GitHub Desktop.
CCS C Timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "main.h" | |
#define LED PIN_C0 | |
#int_TIMER0 | |
void Ngat_TIMER0(void) | |
{ | |
fprintf(PORT1,"Ngat timer 0\r\n"); | |
} | |
#int_TIMER1 | |
void Ngat_TIMER1(void) | |
{ | |
output_toggle(PIN_C1);//Ham dao trang thai | |
} | |
#int_TIMER2 | |
void Ngat_TIMER2(void) | |
{ | |
output_toggle(PIN_C1);//Ham dao trang thai | |
} | |
void main() | |
{ | |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128); //1.6 s overflow//tang gia tri sau 0.2us | |
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //13.1 ms overflow//tang sau 0.2us | |
fprintf(PORT1,"HiThere"); | |
//enable_interrupts(INT_TIMER0);//cho phep ngat timer0 | |
//enable_interrupts(INT_TIMER1);//cho phep ngat timer1 | |
setup_timer_2(T2_DIV_BY_1,5,5); | |
enable_interrupts(INT_TIMER2); | |
enable_interrupts(GLOBAL); | |
/* | |
setup_timer_2 (mode, period, postscale) | |
setup_timer_2(T2_DIV_BY_1,4,1); | |
Timer 2 tuong duong voi : mode: Khong chia tan so(tan so =5mhz) | |
period: 4(Gia tri de timer reset laij ve 0: 0-255 | |
postscale =1( so lan de xay ra ngat sau khi reset) 0-16 | |
gia tri tang sau 1 xung 0.2us | |
khi tang 4 xung thi timer bi reset | |
Tinhs ra so lan tran timer trong 1 s la: 1/((0.2*4*1)*10^-6)=1250000 | |
tan so cua chan 1250000/2=625000 | |
------------Tinh cho xung 1khz tren chan c1-timmer 2 can tran 2000 lan /2 | |
chonh mode ko chia tan so- 1 gia tri timer tang 0.2us | |
-> period=250 | |
1 lan reset timer ma 250*0.2=50us | |
postscale=10//setup_timer_2(T2_DIV_BY_1,250,10); | |
//Tao xung 100k | |
setup_timer_2(T2_DIV_BY_1,5,5); | |
*/ | |
while(TRUE) | |
{ | |
output_high(PIN_C0); | |
delay_ms(100); | |
output_low(LED); | |
delay_ms(100); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<18f4520.h> | |
#device adc=10 | |
#FUSES NOWDT //No Watch Dog Timer | |
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale | |
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD) | |
#FUSES NOBROWNOUT //No brownout reset | |
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O | |
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) | |
#use delay(clock=20000000) | |
#use rs232(baud=9600,parity=N,xmit=PIN_D0,rcv=PIN_D1,bits=8,stream=PORT1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment