feat: 06-17 신규 작업본 반영 (개발사양서/기능검토/승인원/Source 등 추가)
.claude/ 제외(.gitignore 추가). 기존 초기커밋(5a96a69) 위에 신규·수정·이동분 커밋.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,478 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "Nano100Series.h"
|
||||
#include "adc.h"
|
||||
#include "gpio.h"
|
||||
#include "pwm.h"
|
||||
#include "timer.h"
|
||||
#include "uart.h"
|
||||
#include "sys.h"
|
||||
#include "clk.h"
|
||||
#include "EEPROM_Emulate.h"
|
||||
|
||||
|
||||
#include "My_define.h"
|
||||
|
||||
|
||||
|
||||
void delay_us(uint32_t us)
|
||||
{
|
||||
CLK_SysTickDelay(us);
|
||||
}
|
||||
|
||||
|
||||
void delay_ms(uint32_t ms)
|
||||
{
|
||||
while(ms--)
|
||||
{
|
||||
delay_us(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UART0_Init()//co2
|
||||
{
|
||||
/*---------------------------------------------------------------------------------------------------------*/
|
||||
/* Init UART */
|
||||
/*---------------------------------------------------------------------------------------------------------*/
|
||||
SYS_ResetModule(UART0_RST);
|
||||
UART_Open(UART0, 115200);
|
||||
|
||||
|
||||
UART_EnableInt(UART0, UART_IER_RDA_IE_Msk);
|
||||
NVIC_EnableIRQ(UART0_IRQn);
|
||||
}
|
||||
|
||||
|
||||
void UART1_Init()
|
||||
{
|
||||
/*---------------------------------------------------------------------------------------------------------*/
|
||||
/* Init UART */
|
||||
/*---------------------------------------------------------------------------------------------------------*/
|
||||
SYS_ResetModule(UART1_RST);
|
||||
UART_Open(UART1, 115200);
|
||||
|
||||
UART_EnableInt(UART1, UART_IER_RDA_IE_Msk);
|
||||
NVIC_EnableIRQ(UART1_IRQn);
|
||||
}
|
||||
|
||||
void SC0_Init() // to main
|
||||
{
|
||||
SCUART_Open(SC0, 1200);
|
||||
// Enable smartcard receive interrupt
|
||||
SCUART_ENABLE_INT(SC0, SC_IER_RDA_IE_Msk);
|
||||
NVIC_EnableIRQ(SC0_IRQn);
|
||||
}
|
||||
|
||||
|
||||
void SC1_Init() // to dust
|
||||
{
|
||||
SCUART_Open(SC1, 9600);
|
||||
// Enable smartcard receive interrupt
|
||||
SCUART_ENABLE_INT(SC1, SC_IER_RDA_IE_Msk);
|
||||
NVIC_EnableIRQ(SC1_IRQn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void PowerDownFunction(void)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define IR_EVENT_POWER 0x01
|
||||
#define IR_EVENT_MODE 0x02
|
||||
#define IR_EVENT_WIND_UP 0x04
|
||||
#define IR_EVENT_WIND_DN 0x05
|
||||
#define IR_EVENT_TIME_1 0x06
|
||||
#define IR_EVENT_TIME_2 0x07
|
||||
#define IR_EVENT_TIME_3 0x08
|
||||
#define IR_EVENT_FILTER_RESET 0x09
|
||||
|
||||
#define IR_START 13500
|
||||
#define IR_HIGH 2260
|
||||
#define IR_LOW 1180
|
||||
#define IR_STOP 600
|
||||
#define IR_REPEAT 11200
|
||||
|
||||
uint16_t long_timer1 = 0;
|
||||
uint16_t remocon_buff[4];
|
||||
uint8_t remocon_pos = 0;
|
||||
uint8_t remocon_bit_count = 0;
|
||||
|
||||
uint8_t IR_Event_Code = 0;
|
||||
volatile uint8_t IR_Event_Flag = 0;
|
||||
void IR_Receive(void)
|
||||
{
|
||||
uint16_t tmp = 0;
|
||||
|
||||
long_timer1 = TIMER2->DR/12;
|
||||
TIMER2->CTL |= TIMER_CTL_SW_RST_Msk;
|
||||
TIMER_Start(TIMER2);
|
||||
|
||||
if((long_timer1 > IR_START-300)&&(long_timer1 < IR_START+300))
|
||||
{
|
||||
remocon_buff[0] = 0;
|
||||
remocon_buff[1] = 0;
|
||||
remocon_bit_count = 0;
|
||||
remocon_pos = 0;
|
||||
}
|
||||
else if((long_timer1 > IR_REPEAT-300)&&(long_timer1 < IR_REPEAT+300))
|
||||
{
|
||||
remocon_buff[0] = 0;
|
||||
remocon_buff[1] = 0;
|
||||
remocon_bit_count = 0;
|
||||
remocon_pos = 0;
|
||||
}
|
||||
else if((long_timer1 > IR_HIGH-200)&&(long_timer1 < IR_HIGH+200))
|
||||
{
|
||||
remocon_buff[remocon_pos] |= 0x8000;
|
||||
if(remocon_bit_count++ >= 15){remocon_bit_count = 0;remocon_pos=1;}
|
||||
else {remocon_buff[remocon_pos] >>= 1;}
|
||||
}
|
||||
else if((long_timer1 > IR_LOW-200)&&(long_timer1 < IR_LOW+200))
|
||||
{
|
||||
remocon_buff[remocon_pos] &= ~0x8000;
|
||||
if(remocon_bit_count++ >= 15){remocon_bit_count = 0;remocon_pos=1;}
|
||||
else {remocon_buff[remocon_pos] >>= 1;}
|
||||
}
|
||||
|
||||
if((remocon_pos == 1)&&(remocon_bit_count == 15))
|
||||
{
|
||||
if(remocon_buff[0] == 0xA55A)
|
||||
{
|
||||
tmp = remocon_buff[1];
|
||||
/* switch(tmp)
|
||||
{
|
||||
case 0x6E11: // Power
|
||||
IR_Event_Code = IR_EVENT_POWER;
|
||||
break;
|
||||
case 0x6D12: // mode
|
||||
IR_Event_Code = IR_EVENT_MODE;
|
||||
break;
|
||||
case 0x6C13: // up
|
||||
IR_Event_Code = IR_EVENT_WIND_UP;
|
||||
break;
|
||||
case 0x6817: // dn
|
||||
IR_Event_Code = IR_EVENT_WIND_DN;
|
||||
break;
|
||||
case 0x6718: // 1hour
|
||||
IR_Event_Code = IR_EVENT_TIME_1 ;
|
||||
break;
|
||||
case 0x6619: // 2hour
|
||||
IR_Event_Code = IR_EVENT_TIME_2 ;
|
||||
break;
|
||||
case 0x215E: // 3hour
|
||||
IR_Event_Code = IR_EVENT_TIME_3 ;
|
||||
break;
|
||||
case 0x354A: // filter reset
|
||||
IR_Event_Code = IR_EVENT_FILTER_RESET;
|
||||
break;
|
||||
default:
|
||||
IR_Event_Code = 0;
|
||||
break;
|
||||
}
|
||||
if(IR_Event_Code)
|
||||
{
|
||||
IR_Event_Flag = 1;
|
||||
}
|
||||
*/
|
||||
}
|
||||
remocon_buff[0] = 0;
|
||||
remocon_buff[1] = 0;
|
||||
remocon_bit_count = 0;
|
||||
remocon_pos = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
volatile uint8_t Touch_Event = 0;
|
||||
|
||||
void GPABC_IRQHandler(void)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
if(GPIO_GET_INT_FLAG(PB, BIT12))
|
||||
{
|
||||
GPIO_CLR_INT_FLAG(PB, BIT12);
|
||||
CLK->WK_INTSTS = 1; /* clear interrupt status */
|
||||
if(PB12 == 0)Touch_Event = 1;
|
||||
else Touch_Event = 2;
|
||||
}
|
||||
else if(GPIO_GET_INT_FLAG(PB, BIT14))
|
||||
{
|
||||
GPIO_CLR_INT_FLAG(PB, BIT14);
|
||||
CLK->WK_INTSTS = 1; /* clear interrupt status */
|
||||
IR_Receive();
|
||||
}
|
||||
else
|
||||
{
|
||||
reg = PA->ISRC; PA->ISRC = reg;
|
||||
reg = PB->ISRC; PB->ISRC = reg;
|
||||
reg = PC->ISRC; PC->ISRC = reg;
|
||||
}
|
||||
}
|
||||
|
||||
volatile uint8_t Run_Timer = 0;
|
||||
volatile uint16_t mSec_Timer = 0;
|
||||
volatile uint16_t Blink_Timer = 0;
|
||||
volatile uint8_t Rx_FND_TimeOut = 0;
|
||||
volatile uint16_t FastBlink_Timer = 0;
|
||||
|
||||
void TMR0_IRQHandler(void)
|
||||
{
|
||||
if(Run_Timer)Run_Timer--;
|
||||
if(mSec_Timer)mSec_Timer--;
|
||||
if(Blink_Timer)Blink_Timer--;
|
||||
if(FastBlink_Timer)FastBlink_Timer--;
|
||||
if(Rx_FND_TimeOut)Rx_FND_TimeOut--;
|
||||
|
||||
|
||||
// clear timer interrupt flag
|
||||
TIMER_ClearIntFlag(TIMER0);
|
||||
}
|
||||
|
||||
// TIMER_ClearWakeupFlag(TIMER0);
|
||||
void Timer0_Init(void)
|
||||
{
|
||||
TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 1000); // 1ms -> HZ
|
||||
|
||||
// Enable timer interrupt
|
||||
TIMER_EnableInt(TIMER0);
|
||||
NVIC_EnableIRQ(TMR0_IRQn);
|
||||
|
||||
|
||||
// Start Timer 0
|
||||
TIMER_Start(TIMER0);
|
||||
}
|
||||
|
||||
|
||||
void TMR1_IRQHandler(void)
|
||||
{
|
||||
// clear timer interrupt flag
|
||||
TIMER_ClearIntFlag(TIMER1);
|
||||
}
|
||||
|
||||
void Timer1_Init(void)
|
||||
{
|
||||
TIMER_Open(TIMER1, TIMER_PERIODIC_MODE, 100); // 10ms -> HZ
|
||||
|
||||
// Enable timer interrupt
|
||||
TIMER_EnableInt(TIMER1);
|
||||
NVIC_EnableIRQ(TMR1_IRQn);
|
||||
|
||||
|
||||
// Start Timer 0
|
||||
TIMER_Start(TIMER1);
|
||||
}
|
||||
void Timer2_Init(void) ///////////////////////////////////////////////////////////////////
|
||||
{
|
||||
TIMER_Open(TIMER2, TIMER_PERIODIC_MODE, 1); // 1000ms -> HZ
|
||||
|
||||
// Enable timer interrupt
|
||||
TIMER_EnableInt(TIMER2);
|
||||
// NVIC_EnableIRQ(TMR2_IRQn);
|
||||
|
||||
|
||||
// Start Timer 0
|
||||
TIMER_Start(TIMER2);
|
||||
}/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void PWM_Init(void)
|
||||
{
|
||||
// PWM0 frequency is 300Hz, duty 50%
|
||||
// PWM_ConfigOutputChannel(PWM0, 3, 960, 50); // LCD Backlight
|
||||
PWM_ConfigOutputChannel(PWM1, 0, 100, 0); // buzzer
|
||||
|
||||
// Enable output of all PWM channels
|
||||
// PWM_EnableOutput(PWM0, 1<<3); // ch3
|
||||
PWM_EnableOutput(PWM1, 0x01);
|
||||
|
||||
// Start
|
||||
// PWM_Start(PWM0, 1<<3); // pwm0_ch3
|
||||
PWM_Start(PWM1, 0x01);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
volatile uint32_t ADC3_Value = 0;;
|
||||
void ADC_IRQHandler(void)
|
||||
{
|
||||
uint32_t u32Flag;
|
||||
|
||||
// Get ADC conversion finish interrupt flag
|
||||
u32Flag = ADC_GET_INT_FLAG(ADC, ADC_ADF_INT);
|
||||
|
||||
if(u32Flag & ADC_ADF_INT)
|
||||
{
|
||||
ADC3_Value = ADC_GET_CONVERSION_DATA(ADC, 3);
|
||||
}
|
||||
ADC_CLR_INT_FLAG(ADC, u32Flag);
|
||||
|
||||
}
|
||||
|
||||
void ADC_Init(void)
|
||||
{
|
||||
|
||||
// Enable channel 1
|
||||
ADC_Open(ADC, ADC_INPUT_MODE_SINGLE_END, ADC_OPERATION_MODE_SINGLE, ADC_CH_1_MASK);
|
||||
|
||||
// Set reference voltage to AVDD
|
||||
ADC_SET_REF_VOLTAGE(ADC, ADC_REFSEL_POWER);
|
||||
|
||||
|
||||
// Power on ADC
|
||||
ADC_POWER_ON(ADC);
|
||||
|
||||
// Enable ADC ADC_IF interrupt
|
||||
ADC_EnableInt(ADC, ADC_ADF_INT);
|
||||
NVIC_EnableIRQ(ADC_IRQn);
|
||||
|
||||
|
||||
ADC_START_CONV(ADC);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GPIO_Init(void)
|
||||
{
|
||||
GPIO_SetMode(PA, BIT11, GPIO_PMD_OUTPUT); // ST
|
||||
ST_LED = 0;
|
||||
|
||||
GPIO_SetMode(PA, BIT2|BIT3|BIT4, GPIO_PMD_OUTPUT); // A_2002
|
||||
PA2 = 0;
|
||||
PA3 = 0;
|
||||
PA4 = 0;
|
||||
|
||||
GPIO_SetMode(PA, BIT1, GPIO_PMD_OUTPUT); // power
|
||||
FND_POWER = 0;
|
||||
}
|
||||
|
||||
void SYS_Init(void)
|
||||
{
|
||||
/* Unlock protected registers */
|
||||
SYS_UnlockReg();
|
||||
|
||||
/* Enable clock source */
|
||||
CLK_EnableXtalRC(CLK_PWRCTL_LIRC_EN_Msk|CLK_PWRCTL_HIRC_EN_Msk);
|
||||
|
||||
/* Waiting for clock source ready */
|
||||
CLK_WaitClockReady(CLK_CLKSTATUS_LIRC_STB_Msk|CLK_CLKSTATUS_HIRC_STB_Msk);
|
||||
|
||||
/* If the defines do not exist in your project, please refer to the related clk.h in the Header folder appended to the tool package. */
|
||||
/* Set HCLK clock */
|
||||
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_HCLK_CLK_DIVIDER(1));
|
||||
|
||||
/* Enable IP clock */
|
||||
CLK_EnableModuleClock(GPIO_MODULE);
|
||||
CLK_EnableModuleClock(WDT_MODULE);
|
||||
// CLK_EnableModuleClock(I2C0_MODULE);
|
||||
// CLK_EnableModuleClock(I2C1_MODULE);
|
||||
// CLK_EnableModuleClock(PWM0_CH23_MODULE);
|
||||
// CLK_EnableModuleClock(PWM1_CH01_MODULE);
|
||||
CLK_EnableModuleClock(ISP_MODULE);
|
||||
// CLK_EnableModuleClock(SC0_MODULE);
|
||||
// CLK_EnableModuleClock(SC1_MODULE);
|
||||
CLK_EnableModuleClock(SRAM_MODULE);
|
||||
CLK_EnableModuleClock(TICK_MODULE);
|
||||
CLK_EnableModuleClock(TMR0_MODULE);
|
||||
CLK_EnableModuleClock(TMR1_MODULE);
|
||||
CLK_EnableModuleClock(TMR2_MODULE);
|
||||
CLK_EnableModuleClock(UART0_MODULE);
|
||||
CLK_EnableModuleClock(UART1_MODULE);
|
||||
CLK_EnableModuleClock(WDT_MODULE);
|
||||
|
||||
/* Set IP clock */
|
||||
|
||||
// CLK_SetModuleClock(PWM0_CH23_MODULE, CLK_CLKSEL1_PWM0_CH23_S_HIRC, MODULE_NoMsk);
|
||||
// CLK_SetModuleClock(PWM1_CH01_MODULE, CLK_CLKSEL2_PWM1_CH01_S_HIRC, MODULE_NoMsk);
|
||||
// CLK_SetModuleClock(SC0_MODULE, CLK_CLKSEL2_SC_S_HIRC, CLK_SC0_CLK_DIVIDER(6));
|
||||
// CLK_SetModuleClock(SC1_MODULE, CLK_CLKSEL2_SC_S_HIRC, CLK_SC1_CLK_DIVIDER(1));
|
||||
CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HIRC, MODULE_NoMsk);
|
||||
CLK_SetModuleClock(TMR1_MODULE, CLK_CLKSEL1_TMR1_S_HIRC, MODULE_NoMsk);
|
||||
CLK_SetModuleClock(TMR2_MODULE, CLK_CLKSEL2_TMR2_S_HIRC, MODULE_NoMsk);
|
||||
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HIRC, CLK_UART_CLK_DIVIDER(1));
|
||||
CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UART_S_HIRC, CLK_UART_CLK_DIVIDER(1));
|
||||
CLK_SetModuleClock(WDT_MODULE, 0, 0);
|
||||
|
||||
/* Update System Core Clock */
|
||||
/* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
|
||||
|
||||
//If the defines do not exist in your project, please refer to the corresponding sys.h in the Header folder appended to the tool package.
|
||||
SYS->PA_L_MFP = 0;//SYS_PA_L_MFP_PA5_MFP_ADC_CH5;
|
||||
SYS->PA_H_MFP = 0;
|
||||
SYS->PB_H_MFP = 0;
|
||||
SYS->PB_L_MFP = SYS_PB_L_MFP_PB0_MFP_UART0_RX | SYS_PB_L_MFP_PB1_MFP_UART0_TX |SYS_PB_L_MFP_PB5_MFP_UART1_TX | SYS_PB_L_MFP_PB4_MFP_UART1_RX ;
|
||||
SYS->PC_H_MFP = 0x00000000;
|
||||
SYS->PC_L_MFP = 0x00000000;
|
||||
SYS->PD_H_MFP = 0x00000000;
|
||||
SYS->PD_L_MFP = 0x00000000;
|
||||
SYS->PE_L_MFP = 0x00000000;
|
||||
SYS->PF_L_MFP = SYS_PF_L_MFP_PF1_MFP_ICE_CLK | SYS_PF_L_MFP_PF0_MFP_ICE_DAT;
|
||||
|
||||
|
||||
|
||||
/* Lock protected registers */
|
||||
SYS_LockReg();
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
extern uint8_t Main_Modbus_ID;
|
||||
|
||||
void Processor_Init(void)
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7 8 9 , ' ' , E , A
|
||||
|
||||
uint8_t eep_check[20];
|
||||
uint8_t i;
|
||||
|
||||
|
||||
Disp_Segdata(0, 8, 8, 8, 8);
|
||||
Display_process();
|
||||
|
||||
delay_ms(2000);
|
||||
|
||||
Disp_Segdata(0, 16, 13, FND_VERSION>>4, FND_VERSION&0x0F); // R-01
|
||||
Display_process();
|
||||
|
||||
delay_ms(2000);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
for(i=0; i<10; i++)
|
||||
{
|
||||
Read_Data(i, &eep_check[i]);
|
||||
}
|
||||
|
||||
if((eep_check[EEP_ADDR_START] == 0x55)&&(eep_check[EEP_ADDR_START+1] == 0xAA))
|
||||
{
|
||||
// Main_Modbus_ID = eep_check[EEP_ADDR_MODBUS_ID];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Write_Data(EEP_ADDR_START, 0x55);
|
||||
Write_Data(EEP_ADDR_START+1, 0xAA);
|
||||
|
||||
// Write_Data(EEP_ADDR_MODBUS_ID, Main_Modbus_ID);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user