/*------- pin_module.c ---------*/
#include "pin_manager.h"
extern uint8_t IrFlg;
void (*IOCAF4_InterruptHandler)(void);
・・・
void IOCAF4_ISR(void) {
IrFlg = 1;
if(IOCAF4_InterruptHandler)
{
IOCAF4_InterruptHandler();
}
IOCAFbits.IOCAF4 = 0;
}
・・・
|
|
/*------- main.c ---------*/
#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/examples/i2c1_master_example.h"
#include <stdio.h>
#include "i2cLCD_AQM0802A.h"
uint16_t aVal;
uint16_t pwmV;
uint8_t trDrc = 1;
uint8_t inDrc = 0;
uint8_t IrFlg;
void dsp_sts(uint8_t a){
LCD_cursor(0,0);
switch(a){
case 0:
LCD_str("NoPwr");
break;
case 1:
LCD_str("Ready");
break;
case 2:
LCD_str("Forwd");
break;
case 3:
LCD_str("Revrs");
break;
}
}
void dsp_num(uint8_t x, uint16_t n){
char sBuf[10];
sprintf(sBuf,"%4d",n);
LCD_cursor(x,1);
LCD_str(sBuf);
}
void stop_wait_Vr_Zero(void){
Led_A5_SetHigh();
PWM5_LoadDutyValue(0);
CWG1STR = 0xF5;
pwmV = 0;
dsp_sts(0);
dsp_num(0, pwmV);
do{
aVal = ADC_GetConversion(Vr_C5);
dsp_num(4, aVal);
}while(aVal > 0);
Led_A5_SetLow();
dsp_sts(trDrc + 2);
}
/* ==== Main application ==== */
void main(void){
SYSTEM_Initialize();
INTERRUPT_GlobalInterruptEnable();
INTERRUPT_PeripheralInterruptEnable();
DACCON1 = 0x03;
LCD_init();
stop_wait_Vr_Zero();
while (1)
{
if(CWG1AS0bits.CWG1SHUTDOWN || IrFlg){
stop_wait_Vr_Zero();
CWG1_AutoShutdownEventClear();
trDrc ^= 0x01;
IrFlg = 0;
}
if(Ps_A3_PORT == 0){
inDrc ^= 0x01;
}
if(trDrc != inDrc){
stop_wait_Vr_Zero();
trDrc = inDrc;
if(trDrc == 0){
CWG1STR = 0xF1;
}else{
CWG1STR = 0xF4;
}
}
aVal = ADC_GetConversion(Vr_C5);
pwmV = aVal;
PWM5_LoadDutyValue(pwmV);
dsp_num(0,pwmV);
dsp_num(4,aVal);
}
}
|
/*------- i2c_LCD_AQM0802A.h ---------*/
#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/examples/i2c1_master_example.h"
#define I2CLCD_AQM0802A 0x3e
/* LCD library */
void LCD_dat(char chr); // Send Data
void LCD_cmd(char cmd); // Send Command
void LCD_clr(void); // Clera LCD
void LCD_home(void); // Home
void LCD_cursor(int x, int y); //Cursol X,Y
void LCD_str(char *str); // Display Strings
void LCD_init(); // LCD initialize
|
/*------- i2c_LCD_AQM0802A.c ---------*/
#include "i2cLCD_AQM0802A.h"
#define CONTRAST 0x18 // for 5.0V
//#define CONTRAST 0x30 // for 3.3V
#define BOOST 0x00 // for 5.0V Bon=off
//#define BOOST 0x04 // for 3.3V Bon=on
/* LCD library */
void LCD_dat(char chr){
I2C1_Write1ByteRegister(I2CLCD_AQM0802A, 0x40, chr);
__delay_us(30); // 30us
}
void LCD_cmd(char cmd){
I2C1_Write1ByteRegister(I2CLCD_AQM0802A, 0x00, cmd);
if(cmd & 0xFC) // bit6 = 1
__delay_us(30); // 30us
else
__delay_ms(2); // 2ms Clear or Home
}
void LCD_clr(void){
LCD_cmd(0x01);
}
void LCD_home(void){
LCD_cmd(0x02);
}
void LCD_cursor(int x, int y){
if (y == 0)
LCD_cmd((char)(0x80 + x));
else if (y == 1)
LCD_cmd((char)(0xc0 + x));
}
void LCD_str(char *str){
while(*str)
LCD_dat(*str++); //pointer increment
}
void putch(char ch){
LCD_dat(ch);
}
void LCD_init(){
__delay_ms(40); //40ms wait
LCD_cmd(0x38); //8bit,2line
LCD_cmd(0x39); //IS=1 : extention mode set
LCD_cmd(0x14); //Internal OSC Frequency
LCD_cmd(0x70 + (CONTRAST & 0x0F)); //Contrast set
LCD_cmd(0x58 + BOOST + (CONTRAST >> 4));
//Power/ICON/Contrast Control
LCD_cmd(0x6C); //Follower control
__delay_ms(200); //200ms wait
LCD_cmd(0x38); //IS=0 : extention mode cancel
LCD_cmd(0x0C); //Display ON
LCD_cmd(0x01); //Clear Display
__delay_ms(2); //wait more than 1.08ms
}
|