Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <xc.h>
- // CONFIG1H
- #pragma config FOSC = INTIO67 // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
- #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
- #pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
- // CONFIG2L
- #pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
- #pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
- #pragma config BORV = 18 // Brown Out Reset Voltage bits (VBOR set to 1.8 V nominal)
- // CONFIG2H
- #pragma config WDTEN = OFF // Watchdog Timer Enable bit (WDT is controlled by SWDTEN bit of the WDTCON register)
- #pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
- // CONFIG3H
- #pragma config CCP2MX = PORTC // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
- #pragma config PBADEN = OFF // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
- #pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
- #pragma config HFOFST = OFF // HFINTOSC Fast Start-up (The system clock is held off until the HFINTOSC is stable.)
- #pragma config MCLRE = OFF // MCLR Pin Enable bit (RE3 input pin enabled; MCLR disabled)
- // CONFIG4L
- #pragma config STVREN = OFF // Stack Full/Underflow Reset Enable bit (Stack full/underflow will not cause Reset)
- #pragma config LVP = ON // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
- #pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
- // CONFIG5L
- #pragma config CP0 = OFF // Code Protection Block 0 (Block 0 (000800-001FFFh) not code-protected)
- #pragma config CP1 = OFF // Code Protection Block 1 (Block 1 (002000-003FFFh) not code-protected)
- #pragma config CP2 = OFF // Code Protection Block 2 (Block 2 (004000-005FFFh) not code-protected)
- #pragma config CP3 = OFF // Code Protection Block 3 (Block 3 (006000-007FFFh) not code-protected)
- // CONFIG5H
- #pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
- #pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
- // CONFIG6L
- #pragma config WRT0 = OFF // Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected)
- #pragma config WRT1 = OFF // Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected)
- #pragma config WRT2 = OFF // Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected)
- #pragma config WRT3 = OFF // Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected)
- // CONFIG6H
- #pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
- #pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
- #pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
- // CONFIG7L
- #pragma config EBTR0 = OFF // Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
- #pragma config EBTR1 = OFF // Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
- #pragma config EBTR2 = OFF // Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
- #pragma config EBTR3 = OFF // Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)
- // CONFIG7H
- #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
- #define led1red LATAbits.LATA4
- #define led1green LATAbits.LATA5
- #define led1blue LATEbits.LATE0
- #define led2red LATEbits.LATE1
- #define led2green LATEbits.LATE2
- #define led2blue LATAbits.LATA7
- #define led3red LATAbits.LATA6
- #define led3green LATCbits.LATC0
- #define led3blue LATCbits.LATC1
- #define led4red LATCbits.LATC2
- #define led4green LATCbits.LATC3
- #define led4blue LATDbits.LATD0
- #define led5red LATDbits.LATD1
- #define led5green LATDbits.LATD2
- #define led5blue LATDbits.LATD3
- #define led6red LATCbits.LATC4
- #define led6green LATCbits.LATC6
- #define led6blue LATDbits.LATD4
- #define led7red LATDbits.LATD5
- #define led7green LATDbits.LATD6
- #define led7blue LATDbits.LATD7
- #define led8red LATBbits.LATB0
- #define led8green LATBbits.LATB1
- #define led8blue LATBbits.LATB2
- #define led9red LATBbits.LATB3
- #define led9green LATBbits.LATB4
- #define led9blue LATBbits.LATB5
- //demas pines utilizados
- #define MCLR PORTEbits.RE3
- #define PGC LATBbits.LATB6
- #define PGD LATBbits.LATB7
- #define ANALOG0 PORTAbits.RA0
- #define ANALOG1 PORTAbits.RA1
- #define ANALOG2 PORTAbits.RA2
- #define ANALOG3 PORTAbits.RA3
- #define duty1red dutys[0]
- #define duty1green dutys[1]
- #define duty1blue dutys[2]
- #define duty2red dutys[3]
- #define duty2green dutys[4]
- #define duty2blue dutys[5]
- #define duty3red dutys[6]
- #define duty3green dutys[7]
- #define duty3blue dutys[8]
- #define duty4red dutys[9]
- #define duty4green dutys[10]
- #define duty4blue dutys[11]
- #define duty5red dutys[12]
- #define duty5green dutys[13]
- #define duty5blue dutys[14]
- #define duty6red dutys[15]
- #define duty6green dutys[16]
- #define duty6blue dutys[17]
- #define duty7red dutys[18]
- #define duty7green dutys[19]
- #define duty7blue dutys[20]
- #define duty8red dutys[21]
- #define duty8green dutys[22]
- #define duty8blue dutys[23]
- #define duty9red dutys[24]
- #define duty9green dutys[25]
- #define duty9blue dutys[26]
- unsigned char anchodepulso=0;
- unsigned char dutys[27] = { 245,100,100,
- 10,10,10,
- 10,10,10,
- 10,10,10,
- 10,10,10,
- 10,150,10,
- 10,10,10,
- 10,10,10,
- 100,100,100
- };
- //pragma usado en xc18
- /*
- void myISR_Low(void);
- void myISR_High(void);
- *
- * #pragma code HIGH_INTERRUPT_VECTOR = 0x08
- void High_ISR (void){
- _asm goto myISR_High _endasm
- }
- #pragma code LOW_INTERRUPT_VECTOR = 0x18
- void Low_ISR (void){
- _asm goto myISR_Low _endasm
- }
- */
- void interrupt YourHighPriorityISRCode(){
- if(INTCONbits.TMR0IF){
- //INTCONbits.TMR0IE=0;
- anchodepulso++;
- if(anchodepulso<=duty1red){
- led1red=1;
- }else led1red=0;
- if(anchodepulso<=duty1green){
- led1green=1;
- }else led1green=0;
- if(anchodepulso<=duty1blue){
- led1blue=1;
- }else led1blue=0;
- if(anchodepulso<=duty2red){
- led2red=1;
- }else led2red=0;
- if(anchodepulso<=duty2green){
- led2green=1;
- }else led2green=0;
- if(anchodepulso<=duty2blue){
- led2blue=1;
- }else led2blue=0;
- if(anchodepulso<=duty3red){
- led3red=1;
- }else led3red=0;
- if(anchodepulso<=duty3green){
- led3green=1;
- }else led3green=0;
- if(anchodepulso<=duty3blue){
- led3blue=1;
- }else led3blue=0;
- if(anchodepulso<=duty4red){
- led4red=1;
- }else led4red=0;
- if(anchodepulso<=duty4green){
- led4green=1;
- }else led4green=0;
- if(anchodepulso<=duty4blue){
- led4blue=1;
- }else led4blue=0;
- if(anchodepulso<=duty5red){
- led5red=1;
- }else led5red=0;
- if(anchodepulso<=duty5green){
- led5green=1;
- }else led5green=0;
- if(anchodepulso<=duty5blue){
- led5blue=1;
- }else led5blue=0;
- if(anchodepulso<=duty6red){
- led6red=1;
- }else led6red=0;
- if(anchodepulso<=duty6green){
- led6green=1;
- }else led6green=0;
- if(anchodepulso<=duty6blue){
- led6blue=1;
- }else led6blue=0;
- if(anchodepulso<=duty7red){
- led7red=1;
- }else led7red=0;
- if(anchodepulso<=duty7green){
- led7green=1;
- }else led7green=0;
- if(anchodepulso<=duty7blue){
- led7blue=1;
- }else led7blue=0;
- if(anchodepulso<=duty8red){
- led8red=1;
- }else led8red=0;
- if(anchodepulso<=duty8green){
- led8green=1;
- }else led8green=0;
- if(anchodepulso<=duty8blue){
- led8blue=1;
- }else led8blue=0;
- if(anchodepulso<=duty9red){
- led9red=1;
- }else led9red=0;
- if(anchodepulso<=duty9green){
- led9green=1;
- }else led9green=0;
- if(anchodepulso<=duty9blue){
- led9blue=1;
- }else led9blue=0;
- if(anchodepulso==255){
- anchodepulso==0;
- }
- //INTCONbits.TMR0IE=1;
- //TMR0=255;
- if(anchodepulso == 32) anchodepulso = 0;
- INTCONbits.TMR0IF=0;
- TMR0L = 200;
- }
- INTCONbits.GIE_GIEH=1; //IMPORTANTE HABILITARLAS PORQ SE DESHABILITAN CON INTERRUP
- }
- /*
- void interrupt low_priority YourLowPriorityISRCode(){
- INTCONbits.PEIE_GIEL=0;//IMPORTANTE HABILITARLAS PORQ SE DESHABILITAN CON INTERRUP
- }
- */
- void main(void) {
- OSCCONbits.IDLEN=0;
- OSCCONbits.IRCF =0b111; //oscilador interno de 16Mhz
- while(OSCCONbits.OSTS); // sino esta corriendo con oscilador interno quedarse aca
- while(!OSCCONbits.IOFS); // espera que frecuencia del clok sea estable
- OSCCONbits.SCS = 0b11; // clock del sistema sea interno
- OSCTUNEbits.INTSRC=1;
- OSCTUNEbits.PLLEN= 1; //habilito PLL osea que en 16Mhz con PLL DE 4 --> Fosc= 64MHz
- OSCTUNEbits.TUN= 0; //oscilador funcione calibrado de fabrica
- INTCONbits.TMR0IE=0;
- INTCONbits.INT0IE = 0;
- INTCONbits.RBIE = 0;
- INTCONbits.PEIE_GIEL=1;
- INTCONbits.GIE_GIEH=1;
- INTCON2bits.RBPU=0;
- INTCON2bits.TMR0IP=1;
- INTCON2bits.RBIP=0;
- INTCON3bits.INT2E=0;
- INTCON3bits.INT1E=0;
- INTCON3bits.INT1IP=0;
- INTCON3bits.INT2IP=0;
- PIE1bits.ADIE=0;
- PIE1bits.PSPIE=0;
- PIE1bits.RCIE=0; //INT DEL EUSART
- PIE1bits.TXIE=0; //INT DEL EUSART
- PIE1bits.CCP1IE=0;
- PIE1bits.TMR1IE=0;
- PIE1bits.TMR2IE=0;
- PIE2bits.BCLIE=0;
- PIE2bits.C1IE=0;
- PIE2bits.C2IE=0;
- PIE2bits.EEIE=0;
- PIE2bits.HLVDIE=0;
- PIE2bits.TMR3IE=0;
- PIE2bits.CCP2IE=0;
- TRISB = 0b00000000; // 6 PWM DOS OCUPADOS POR PROGRAMACION RB6 Y RB7
- TRISC = 0b10000000; // 6 PWM DOS OCUPADOS POR USART RC6 Y RC7
- TRISD = 0b00000000; // 8 PWM
- TRISE = 0b1000; // 3 PWM RE3 ES MCLR
- TRISA = 0b00000011; // 4 PWM , SOBRAN 4 ADC RA0 RA1 RA2 Y RA3
- T0CONbits.T08BIT = 1;
- T0CONbits.T0CS=0;
- T0CONbits.PSA= 1; // SIN PRESCALER OSEA PRESCALER =1
- TMR0L= 244; // desborda cada 75uS , cuando llega a 100 veces cumple un periodo de 13,333 KHz
- TMR0H = 0;
- INTCONbits.TMR0IE=1;
- INTCONbits.TMR0IF = 0;
- INTCONbits.PEIE_GIEL=0;
- while(1){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement