Các anh các bạn các vị tiền bối ơi, sao em đọc thấy nhiều topic nói mà ko thấy trả lời.
CCS có hổ trợ compiler cho dsPIC ko vậy ạ.
Em cảm ơn.
CCS có hổ trợ compiler cho dsPIC ko vậy ạ.
Em cảm ơn.
#include <16f877a.h>
#include <def_877a.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=8000000)
#include <lcd_lib_4bit.c>
int16 cnt,cnt2,xung,v;
int8 a,b,c;
#int_TIMER0
void TIMER0_isr(void) //TIMER0 dem xung ve
{
set_timer0(255);
if(tmr0if==1)
{
cnt++;
tmr0if=0;
}
}
#int_TIMER1 //TIMER1 dem tgian,tinh van toc
void TIMER1_isr(void)
{
set_timer1(5565);
if(tmr1if==1)
{
xung=get_timer0()*4;
v=(xung*60)/((100*60*0.001));
tmr1if=0;
}
}
void Lcd()
{
while(1)
{
a=(int)v/100;
b=(int)(v-a*100)/10;
c=(int)v%10;
LCD_putcmd(0xC0);
LCD_putchar("xung encoder");
LCD_putcmd(0x80);
LCD_putchar(a+48);
LCD_putcmd(0x81);
LCD_putchar(b+48);
LCD_putcmd(0x82);
LCD_putchar(c+48);
}
}
void Ngat()
{
set_timer0(255);
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_4);
enable_interrupts(INT_TIMER0);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
set_timer1(5565);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
}
void PWM()
{
setup_timer_2(T2_DIV_BY_16,255,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty(1000);
set_pwm2_duty(1022);
}
void main()
{
set_tris_d(0);
set_tris_a(0xff); //Cho tin hieu di vao RA4
set_tris_c(0);
LCD_Init();
PWM();
Ngat();
Lcd();
delay_ms(100);
}
. cái này em mô phỏng bên con 8051 thì ngon lành cành đào ạ, hix :|
.
while(TRUE)
{
adcValue = read_adc(); // Get ADC reading
adcHI = (char)((adcValue >> 5)& 0x1f);
adcLO = (char)((adcValue & 0x1f)|0x80);
putc(adcHI);
putc(adcLO);
delay_ms(10); // Preset delay, repeat every 10ms
}
}

Comment