Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*---------------------------------------------/
- | Pulse Generator using TIMER2 |
- | Date modified : 22 March 2012 |
- /---------------------------------------------*/
- #include <htc.h>
- #include <pic16f877a.h>
- #define _XTAL_FREQ 20000000 // Set the oscillator frequency to 20MHz
- void main( )
- {
- TRISC = 0x00; //Port C as outputs
- /* T2CON = 0b0000000;
- /*---------------------------------------------/
- | Timer2 control register
- | Timer2 Output Postscale = 1:11 postscale
- | Timer2 On bit(TMR2ON) = Timer2 is off (0)
- | Timer2 Clock Prescale = Prescaler is 1
- /---------------------------------------------*/
- T2CON = 0b00000001;
- /*---------------------------------------------/
- | Timer2 control register (for 5kHz pulse)
- | Timer2 Output Postscale = 1:11 postscale
- | Timer2 On bit(TMR2ON) = Timer2 is off (0)
- | Timer2 Clock Prescale = Prescaler is 4
- /---------------------------------------------*/
- //PR2 = 0b01111111; //Timer2 increamenr from 00h until 7Fh @ 127
- //PR2 = 0b10100101; // 30kHz
- PR2 = 0b11111001; // 5kHz pulse
- //CCP1CON = 0b00111100;
- /*---------------------------------------------/
- | PWM Least Significant bits = 11b
- | CCPx Mode Select bits = PWM mode
- /---------------------------------------------*/
- CCP1CON = 0b00001100; // 50% duty cycle
- /*---------------------------------------------/
- | PWM Least Significant bits = 00b
- | CCPx Mode Select bits = PWM mode
- /---------------------------------------------*/
- //CCPR1L = 63; // 00111111b
- CCPR1L = 125; // ( 1111101b ) 50% duty cycle
- TMR2ON = 1; //Turn on Timer 2
- while(1); //run, run, run
- } //End of Program
Advertisement
Add Comment
Please, Sign In to add comment