Código feito em CCS C Compiler
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock = 20MHz)
//============== TABELA COM VALORES DE UMA ONDA SENOIDAL ================//
const unsigned int seno[73] = { 0,0,1,2,3,5,7,9,12,14,18,21,25,29,33,37,41,
45,50,54,58,62,66,70,74,78,81,85,87,90,92,94,
96,97,98,99,99,99,98,97,96,94,92,90,87,85,81,
78,74,70,66,62,58,54,50,45,41,37,33,29,25,21,
18,14,12,9,7,5,3,2,1,0};
//======================================================================//
unsigned int8 ii = 0, ton;
#int_RTCC
void RTCC_isr(void){
ii=ii+1; ton = seno[ii];
set_pwm1_duty(ton);
if(ii>71)ii=0;
}
void main(){
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
// Programação do Timer 0 - Overflow a cada 819 us
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
setup_timer_1(T1_DISABLED);
// Programação do Timer 2 - usado no PWM
setup_timer_2(T2_DIV_BY_1,99,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(99); // Ton = 100%
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while(true){
/*
ii=ii+1; ton = seno[ii];
set_pwm1_duty(ton);
if(ii>71)ii=0;
delay_ms(1);
*/
}
}
Nenhum comentário:
Postar um comentário