Skip to content

Instantly share code, notes, and snippets.

@vintagechips
Created June 6, 2015 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vintagechips/b5883f965d340fbf2fe9 to your computer and use it in GitHub Desktop.
Save vintagechips/b5883f965d340fbf2fe9 to your computer and use it in GitHub Desktop.
PIC12F1822 application for baud rate generator(9600bps * 16 = 153600Hz).
//baud rate generator
//device: PIC12F1822(5V)
//compiler: HI-TECH PICC 9.80a
#include <pic.h>
__CONFIG(FOSC_INTOSC & WDTE_OFF);
void main(){
OSCCON = 0b11110000; //32MHz
OSCTUNE = 63; //tune
ANSELA = 0; //digital
TRISA = 0; //output
CCP1CON = 0b00001100; //PWM mode
PR2 = 51; //PWM cycle
CCPR1L = PR2 / 2; //duty cycle
CCPR1H = PR2 / 2; //initial duty cycle
T2CON = 0; //not use prescale
TMR2 = 0; //TMR2 clear
TMR2ON = 1; //TMR2 start
while(1){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment