#include "derivative.h"
#include "Driver_SLCD.h"
#include "string.h"
#include "stdio.h"
#define FTM1_MOD_VALUE 24000
void _PWM(float DutyCycle);
void initPWM();
extern int LPTMR_INTERRUPT;
extern int int_counter;
extern void lptmr_interrupt();
extern void time_delay();
extern void initPIT();
void printLCDString(char *str);
int main(void)
{
STRING str = "KAIXO";
printf("String %s\n", str);
_SLCDModule_Init();
_SLCDModule_PrintString(str, 0);
char str_number[100];
printf("\n'H' 'o' 'l' 'a': %d\n", int_counter);
lptmr_interrupt();
time_delay();
printf("\nAfter delay int_counter: %d\n", int_counter);
_SLCDModule_ClearLCD(0);
STRING str_seg = "SEG";
_SLCDModule_PrintString(str_seg, 18);
int_counter = 0;
for(; {
if(LPTMR_INTERRUPT == 1){
LPTMR_INTERRUPT = 0;
sprintf(str_number, "%d", int_counter);
_SLCDModule_PrintString(str_number, 0);
printf("counter: %d\n", int_counter);
}
}
return 0;
}
void initPWM(){
SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK;
PORTA_PCR8 = PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK;
FTM1_MODE |= FTM_MODE_WPDIS_MASK;
FTM1_MODE &= ~1;
FTM1_QDCTRL &=~FTM_QDCTRL_QUADEN_MASK;
FTM1_CNT = 0x0;
FTM1_MOD = FTM1_MOD_VALUE;
FTM1_CNTIN = 0;
FTM1_C0SC |= FTM_CnSC_ELSB_MASK;
FTM1_C0SC &= ~FTM_CnSC_ELSA_MASK;
FTM1_C0SC |= FTM_CnSC_MSB_MASK;
FTM1_C0V = FTM1_MOD_VALUE;
FTM1_SC = FTM_SC_PS(0) | FTM_SC_CLKS(1);
}
void _PWM(float DutyCycle){
float D = DutyCycle*0.01;
FTM1_C0V = (int) ((1.0-D) * (float)FTM1_MOD_VALUE);
}