Skip to content

Instantly share code, notes, and snippets.

@gbarros
Created June 21, 2016 13:00
Show Gist options
  • Save gbarros/c3228530fb297c634f2f98b7bb893f25 to your computer and use it in GitHub Desktop.
Save gbarros/c3228530fb297c634f2f98b7bb893f25 to your computer and use it in GitHub Desktop.
long rotacoes = 0;
char strLCD[16] = "0";
char read[4]={0,10,13,'\0'};
// LCD module connections
sbit LCD_RS at RE2_bit;
sbit LCD_EN at RE1_bit;
sbit LCD_D0 at RD0_bit;
sbit LCD_D1 at RD1_bit;
sbit LCD_D2 at RD2_bit;
sbit LCD_D3 at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISE2_bit;
sbit LCD_EN_Direction at TRISE1_bit;
sbit LCD_D0_Direction at TRISD0_bit;
sbit LCD_D1_Direction at TRISD1_bit;
sbit LCD_D2_Direction at TRISD2_bit;
sbit LCD_D3_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
void interrupt(void) {
if (INTCON.TMR0IF) {
TMR0H = 0x85; // 1 segundo
TMR0L = 0xED;
LongToStr(rotacoes*60, strLCD);
rotacoes = 0;
INTCON.TMR0IF = 0;
}
if (PIR1.TMR1IF) {
rotacoes++;
TMR1H = 0XFF;
TMR1L = 0XFF - 8;
PIR1.TMR1IF = 0;
}
}
void main() {
ADCON1 = 0b00001110;
TRISA = 255;
TRISC = 255;
TRISD = 0;
PORTD = 0;
Lcd_Init();
UART1_Init(9600);
/////// INTERRUPT ////////
INTCON.GIE = 1; // global interrupt enable
INTCON.PEIE = 1; // peripheral interrupt enable
T0CON.T08BIT = 0; // 16 bits
T0CON.T0CS = 0;
T0CON.PSA = 0;
T0CON.T0PS2 = 1; // 100 = 1:32 prescale
T0CON.T0PS1 = 0;
T0CON.T0PS0 = 0;
T0CON.TMR0ON = 1;
TMR0H = 0x85; // 1 segundo
TMR0L = 0xED;
INTCON.TMR0IF = 0; // timer0 overflow flag
INTCON.TMR0IE = 1; // timer0 enable
T1CON.RD16 = 0;
T1CON.T1CKPS1 = 0; // 00 = 1:1 prescale
T1CON.T1CKPS0 = 0;
T1CON.TMR1CS = 1; // PORTC.F0 eh o clock
T1CON.TMR1ON = 1;
TMR1H = 0XFF;
TMR1L = 0XFF - 8;
PIR1.TMR1IF = 0; // timer 1 overflow flag
PIE1.TMR1IE = 1; // tiemr 1 enable
//////////////////////////////////////////////
PWM1_Init(20000);
PWM1_Start();
UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);
do {
if (UART1_Data_Ready()) {
read[0] = UART1_Read();
strLCD[3] = read;
switch(read[0])
{
case '0':
PWM1_Set_Duty(88);
read[0] = 'A';
break;
case '1':
PWM1_Set_Duty(128);
read[0] = 'B';
break;
case '2':
PWM1_Set_Duty(224);
read[0] = 'C';
break;
case '3':
PWM1_Set_Duty(255);
read[0] = 'D';
break;
case '4':
PWM1_Set_Duty(0);
UART1_Write_Text("shut down");
read[0] = ' ';
break;
}
UART1_Write_Text(read);
//LCD_Out(2, 2, read);
}
Lcd_Cmd(_LCD_CURSOR_OFF);
LCD_Out(1, 1, strLCD);
delay_ms(100);
} while(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment