Browse Source

dipSwitch

feat/dipSwitch
gudae 2 weeks ago
parent
commit
36736cebd4
  1. BIN
      DefaultBuild/anaout.obj
  2. BIN
      DefaultBuild/cstart.obj
  3. BIN
      DefaultBuild/delay.obj
  4. BIN
      DefaultBuild/dipSwitch.obj
  5. BIN
      DefaultBuild/i2c.obj
  6. BIN
      DefaultBuild/multical.abs
  7. 6
      DefaultBuild/multical.clnk
  8. 653
      DefaultBuild/multical.map
  9. 1267
      DefaultBuild/multical.mot
  10. BIN
      DefaultBuild/owi.obj
  11. BIN
      DefaultBuild/r_cg_adc.obj
  12. BIN
      DefaultBuild/r_cg_adc_user.obj
  13. BIN
      DefaultBuild/r_cg_cgc.obj
  14. BIN
      DefaultBuild/r_cg_cgc_user.obj
  15. BIN
      DefaultBuild/r_cg_port.obj
  16. BIN
      DefaultBuild/r_cg_port_user.obj
  17. BIN
      DefaultBuild/r_cg_serial.obj
  18. BIN
      DefaultBuild/r_cg_serial_user.obj
  19. BIN
      DefaultBuild/r_cg_wdt.obj
  20. BIN
      DefaultBuild/r_cg_wdt_user.obj
  21. BIN
      DefaultBuild/r_main.obj
  22. BIN
      DefaultBuild/r_systeminit.obj
  23. BIN
      DefaultBuild/stkinit.obj
  24. BIN
      DefaultBuild/uart.obj
  25. 298
      QualityReport(multical,DefaultBuild).txt
  26. 110
      anaout.c
  27. 15
      anaout.h
  28. 4
      common.h
  29. 86
      delay.c
  30. 5
      delay.h
  31. 35
      dipSwitch.c
  32. 33
      dipSwitch.h
  33. 487
      i2c.c
  34. 30
      i2c.h
  35. 1096
      multical.COMPUTER1.mtud
  36. 1174
      multical.guseo.mtud
  37. 2385
      multical.mtpj
  38. 188
      multical.rcpe
  39. 886
      owi.c
  40. 48
      owi.h
  41. 161
      r_cg_adc.c
  42. 223
      r_cg_adc.h
  43. 64
      r_cg_adc_user.c
  44. 2
      r_cg_cgc.c
  45. 2
      r_cg_cgc.h
  46. 2
      r_cg_cgc_user.c
  47. 2
      r_cg_macrodriver.h
  48. 63
      r_cg_port.c
  49. 265
      r_cg_port.h
  50. 51
      r_cg_port_user.c
  51. 187
      r_cg_serial.c
  52. 23
      r_cg_serial.h
  53. 181
      r_cg_serial_user.c
  54. 2
      r_cg_userdefine.h
  55. 2
      r_cg_wdt.c
  56. 2
      r_cg_wdt.h
  57. 2
      r_cg_wdt_user.c
  58. 360
      r_main.c
  59. 7
      r_systeminit.c
  60. 182
      uart.c
  61. 37
      uart.h

BIN
DefaultBuild/anaout.obj

Binary file not shown.

BIN
DefaultBuild/cstart.obj

Binary file not shown.

BIN
DefaultBuild/delay.obj

Binary file not shown.

BIN
DefaultBuild/dipSwitch.obj

Binary file not shown.

BIN
DefaultBuild/i2c.obj

Binary file not shown.

BIN
DefaultBuild/multical.abs

Binary file not shown.

6
DefaultBuild/multical.clnk

@ -8,10 +8,16 @@
-Input=DefaultBuild\r_cg_serial_user.obj
-Input=DefaultBuild\r_cg_wdt.obj
-Input=DefaultBuild\r_cg_wdt_user.obj
-Input=DefaultBuild\r_cg_adc.obj
-Input=DefaultBuild\r_cg_adc_user.obj
-Input=DefaultBuild\r_cg_port.obj
-Input=DefaultBuild\r_cg_port_user.obj
-Input=DefaultBuild\anaout.obj
-Input=DefaultBuild\owi.obj
-Input=DefaultBuild\i2c.obj
-Input=DefaultBuild\uart.obj
-Input=DefaultBuild\delay.obj
-Input=DefaultBuild\dipSwitch.obj
-SECURITY_ID=00000000000000000000
-DEVICE=C:\Program Files (x86)\Renesas Electronics\CS+\CC\Device\RL78\Devicefile\DR5F10PPJ.DVF
-DEBug

653
DefaultBuild/multical.map

@ -1,4 +1,4 @@
Renesas Optimizing Linker (W3.07.00 ) 12-Jan-2026 13:17:55
Renesas Optimizing Linker (W3.07.00 ) 14-Jan-2026 10:30:43
*** Options ***
@ -13,10 +13,16 @@ Renesas Optimizing Linker (W3.07.00 ) 12-Jan-2026 13:17:55
-Input=DefaultBuild\r_cg_serial_user.obj
-Input=DefaultBuild\r_cg_wdt.obj
-Input=DefaultBuild\r_cg_wdt_user.obj
-Input=DefaultBuild\r_cg_adc.obj
-Input=DefaultBuild\r_cg_adc_user.obj
-Input=DefaultBuild\r_cg_port.obj
-Input=DefaultBuild\r_cg_port_user.obj
-Input=DefaultBuild\anaout.obj
-Input=DefaultBuild\owi.obj
-Input=DefaultBuild\i2c.obj
-Input=DefaultBuild\uart.obj
-Input=DefaultBuild\delay.obj
-Input=DefaultBuild\dipSwitch.obj
-SECURITY_ID=00000000000000000000
-DEVICE=C:\Program Files (x86)\Renesas Electronics\CS+\CC\Device\RL78\Devicefile\DR5F10PPJ.DVF
-DEBug
@ -38,16 +44,635 @@ Renesas Optimizing Linker (W3.07.00 ) 12-Jan-2026 13:17:55
*** Error information ***
E0562310:Undefined external symbol "_R_ADC_Create" referenced in "DefaultBuild\r_main.obj"
E0562310:Undefined external symbol "_R_ADC_Get_Result" referenced in "DefaultBuild\uart.obj"
E0562310:Undefined external symbol "_R_ADC_Stop" referenced in "DefaultBuild\uart.obj"
E0562310:Undefined external symbol "_R_IICA0_Create" referenced in "DefaultBuild\r_main.obj"
E0562310:Undefined external symbol "_R_IICA0_Create" referenced in "DefaultBuild\i2c.obj"
E0562310:Undefined external symbol "_R_IICA0_Master_Receive" referenced in "DefaultBuild\i2c.obj"
E0562310:Undefined external symbol "_uart_rx_buffer" referenced in "DefaultBuild\r_main.obj"
E0562310:Undefined external symbol "_R_ADC_Start" referenced in "DefaultBuild\uart.obj"
E0562310:Undefined external symbol "_uart_rx_length" referenced in "DefaultBuild\r_main.obj"
E0562310:Undefined external symbol "_R_ADC_Set_OperationOn" referenced in "DefaultBuild\r_main.obj"
E0562310:Undefined external symbol "_uart_rx_index" referenced in "DefaultBuild\r_main.obj"
E0562310:Undefined external symbol "_uart_rx_done" referenced in "DefaultBuild\r_main.obj"
E0562310:Undefined external symbol "_R_IICA0_Master_Send" referenced in "DefaultBuild\i2c.obj"
*** Mapping List ***
SECTION START END SIZE ALIGN
.vect
00000000 0000007f 80 0
.constf
00000080 00000093 14 2
.init_array
00000094 00000094 0 2
.sdata
00000080 00000080 0 2
.option_byte
000000c0 000000c3 4 1
.security_id
000000c4 000000cd a 1
.RLIB
000000c4 000000c4 0 1
.data
000000ce 0000014a 7d 2
.text
0000014b 000002fd 1b3 1
.textf
000002fe 00001cf0 19f3 1
.const
00003000 0000335b 35c 2
.SLIB
0000335c 00005d9d 2a42 1
.bss
000faf00 000fafa3 a4 2
.dataR
000fafa4 000fb020 7d 2
.sbss
000ffe20 000ffe20 0 2
.sdataR
000ffe20 000ffe20 0 2
*** Total Section Size ***
RAMDATA SECTION: 00000121 Byte(s)
ROMDATA SECTION: 0000047b Byte(s)
PROGRAM SECTION: 000045e8 Byte(s)
*** Symbol List ***
SECTION=
FILE= START END SIZE
SYMBOL ADDR SIZE INFO COUNTS OPT
SECTION=.vect
FILE=rlink_generates_03
00000000 0000007f 80
SECTION=.constf
FILE=_REL_print
00000080 00000093 14
SECTION=.option_byte
FILE=rlink_generates_01
000000c0 000000c3 4
SECTION=.security_id
FILE=rlink_generates_02
000000c4 000000cd a
SECTION=.data
FILE=DefaultBuild\r_main.obj
000000ce 00000132 65
FILE=DefaultBuild\i2c.obj
00000134 00000139 6
FILE=DefaultBuild\uart.obj
0000013a 0000014a 11
SECTION=.text
FILE=DefaultBuild\cstart.obj
0000014b 000001bd 73
_start
0000014b 0 none ,g *
_exit
000001bb 0 none ,g *
_atexit
000001bd 0 none ,g *
FILE=DefaultBuild\r_cg_serial_user.obj
000001be 000002f9 13c
_r_uart0_interrupt_receive@1
000001be 5f func ,l *
_r_uart0_interrupt_send@1
0000021d 2f func ,l *
_r_uart1_interrupt_receive@1
0000024c 5f func ,l *
_r_uart1_interrupt_send@1
000002ab 2f func ,l *
_r_iica0_interrupt@1
000002da 20 func ,l *
FILE=DefaultBuild\r_cg_wdt_user.obj
000002fa 000002fb 2
_r_wdt_interrupt@1
000002fa 2 func ,l *
FILE=DefaultBuild\r_cg_adc_user.obj
000002fc 000002fd 2
_r_adc_interrupt@1
000002fc 2 func ,l *
SECTION=.textf
FILE=DefaultBuild\stkinit.obj
000002fe 00000341 44
_stkinit
000002fe 0 none ,g *
LSTINIT1
0000030c 0 none ,l *
LSTINIT2
00000336 0 none ,l *
LSTINIT3
00000341 0 none ,l *
FILE=DefaultBuild\r_main.obj
00000342 00000901 5c0
_hex2byte@1
00000342 34 func ,l *
_handle_uart_command_line
00000376 539 func ,g *
_main
000008af 31 func ,g *
_R_MAIN_UserInit
000008e0 22 func ,g *
FILE=DefaultBuild\r_systeminit.obj
00000902 00000948 47
_R_Systeminit
00000902 42 func ,g *
_hdwinit
00000944 5 func ,g *
FILE=DefaultBuild\r_cg_cgc.obj
00000949 00000972 2a
_R_CGC_Create
00000949 2a func ,g *
FILE=DefaultBuild\r_cg_cgc_user.obj
00000973 00000975 3
_R_CGC_Get_ResetSource
00000973 3 func ,g *
FILE=DefaultBuild\r_cg_serial.obj
00000976 00000c49 2d4
_R_SAU0_Create
00000976 c func ,g *
_R_UART0_Create
00000982 6e func ,g *
_R_UART0_Start
000009f0 26 func ,g *
_R_UART0_Stop
00000a16 1e func ,g *
_R_UART0_Receive
00000a34 18 func ,g *
_R_UART0_Send
00000a4c 26 func ,g *
_R_SAU1_Create
00000a72 c func ,g *
_R_UART1_Create
00000a7e 6e func ,g *
_R_UART1_Start
00000aec 26 func ,g *
_R_UART1_Stop
00000b12 1e func ,g *
_R_UART1_Receive
00000b30 18 func ,g *
_R_UART1_Send
00000b48 26 func ,g *
_R_IICA0_Create
00000b6e 50 func ,g *
_R_IICA0_Stop
00000bbe 5 func ,g *
_R_IICA0_StopCondition
00000bc3 5 func ,g *
_R_IICA0_Master_Send
00000bc8 3f func ,g *
_R_IICA0_Master_Receive
00000c07 43 func ,g *
FILE=DefaultBuild\r_cg_serial_user.obj
00000c4a 00000d06 bd
_r_uart0_callback_receiveend@1
00000c4a 1 func ,l *
_r_uart0_callback_softwareoverrun@1
00000c4b 1 func ,l *
_r_uart0_callback_sendend@1
00000c4c 5 func ,l *
_r_uart0_callback_error@1
00000c51 1 func ,l *
_r_uart1_callback_receiveend@1
00000c52 2e func ,l *
_r_uart1_callback_softwareoverrun@1
00000c80 1 func ,l *
_r_uart1_callback_sendend@1
00000c81 1 func ,l *
_r_uart1_callback_error@1
00000c82 1 func ,l *
_iica0_masterhandler@1
00000c83 84 func ,l *
FILE=DefaultBuild\r_cg_wdt.obj
00000d07 00000d1a 14
_R_WDT_Create
00000d07 10 func ,g *
_R_WDT_Restart
00000d17 4 func ,g *
FILE=DefaultBuild\r_cg_adc.obj
00000d1b 00000dce b4
_R_ADC_Create
00000d1b 91 func ,g *
_R_ADC_Start
00000dac a func ,g *
_R_ADC_Stop
00000db6 a func ,g *
_R_ADC_Set_OperationOn
00000dc0 4 func ,g *
_R_ADC_Set_OperationOff
00000dc4 4 func ,g *
_R_ADC_Get_Result
00000dc8 7 func ,g *
FILE=DefaultBuild\r_cg_port.obj
00000dcf 00000dd5 7
_R_PORT_Create
00000dcf 7 func ,g *
FILE=DefaultBuild\anaout.obj
00000dd6 00000ebb e6
_ANAOUT_AllLow
00000dd6 10 func ,g *
_ANAOUT_Init
00000de6 1e func ,g *
_ANAOUT_Select
00000e04 b8 func ,g *
FILE=DefaultBuild\owi.obj
00000ebc 00001626 76b
_OWI_EnablePower
00000ebc 4 func ,g *
_OWI_DisablePower
00000ec0 3 func ,g *
_GPIO_Clear
00000ec3 b func ,g *
_GPIO_Input
00000ece 7 func ,g *
_GPIO_Read
00000ed5 6 func ,g *
_OWI_Init
00000edb f func ,g *
_OWI_Start
00000eea 16 func ,g *
_OWI_Stop
00000f00 15 func ,g *
_OWI_SecureStop
00000f15 46 func ,g *
_OWI_WriteBit
00000f5b 3a func ,g *
_OWI_WriteByte
00000f95 32 func ,g *
_OWI_ReadBit
00000fc7 50 func ,g *
_OWI_ReadByte
00001017 34 func ,g *
_OWI_T_ReadBytesAndPrint
0000104b c8 func ,g *
_OWI_A_CommandMode
00001113 26c func ,g *
_OWI_Diagnostic
0000137f 102 func ,g *
_OWI_disable
00001481 9 func ,g *
_OWI_T_CommandMode
0000148a 4f func ,g *
_OWI_CommandMode
000014d9 40 func ,g *
_OWI_ReadBytesAndPrint
00001519 10e func ,g *
FILE=DefaultBuild\i2c.obj
00001627 00001ac8 4a2
_disable
00001627 19 func ,g *
_I2C_EnablePower
00001640 4 func ,g *
_I2C_DisablePower
00001644 3 func ,g *
_I2C_A_Command_Mode_receiveData
00001647 213 func ,g *
_I2C_Diagnostic
0000185a e4 func ,g *
_I2C_T_Command_Mode_receiveData
0000193e 37 func ,g *
_I2C_Command_Mode_receiveData
00001975 26 func ,g *
_I2C_Command_Mode_Send
0000199b 12e func ,g *
FILE=DefaultBuild\uart.obj
00001ac9 00001c22 15a
_rs485_set_tx
00001ac9 b func ,g *
_rs485_init
00001ad4 a func ,g *
_uart_send_string
00001ade 22 func ,g *
_uart1_send_string
00001b00 10 func ,g *
_uart_send_hex
00001b10 50 func ,g *
_uart1_send_hex
00001b60 4c func ,g *
_ADC_ReadAndSend_UART
00001bac 77 func ,g *
FILE=DefaultBuild\delay.obj
00001c23 00001cda b8
_delay
00001c23 16 func ,g *
_delay_us
00001c39 7d func ,g *
_delay_ms
00001cb6 25 func ,g *
FILE=DefaultBuild\dipSwitch.obj
00001cdb 00001cf0 16
_DipSwitch_Init
00001cdb 8 func ,g *
_DipSwitch_ReadValue_0to31
00001ce3 9 func ,g *
_DipSwitch_ReadAddr_1to32
00001cec 5 func ,g *
SECTION=.const
FILE=DefaultBuild\r_main.obj
00003000 00003145 146
FILE=DefaultBuild\owi.obj
00003146 000031ff ba
FILE=DefaultBuild\i2c.obj
00003200 00003356 157
FILE=DefaultBuild\uart.obj
00003358 0000335b 4
_ADC_CHANNELS@1@ADC_ReadAndSend_UART
00003358 4 data ,l *
SECTION=.SLIB
FILE=_COM_faddsub
0000335c 00003496 13b
__COM_fsub
000033b8 0 none ,g *
__COM_fadd
000033c0 0 none ,g *
FILE=_COM_fdiv
00003497 000035c4 12e
__COM_fdiv
000034f6 0 none ,g *
FILE=_COM_fmul
000035c5 000036b1 ed
__COM_fmul
00003610 0 none ,g *
FILE=_COM_ftoul
000036b2 000036bd c
__COM_ftoul
000036b2 0 none ,g *
FILE=_COM_ultof
000036be 000036c3 6
__COM_ultof
000036be 0 none ,g *
FILE=isdigit
000036c4 000036cd a
_isdigit
000036c4 0 none ,g *
FILE=memcpy
000036ce 000036dd 10
_memcpy
000036ce 0 none ,g *
FILE=memset
000036de 000036eb e
_memset
000036de 0 none ,g *
FILE=sprintf
000036ec 000037e4 f9
_sprintf
000036ec e1 func ,g *
__REL_sp@1
000037cd 18 func ,l *
FILE=strcpy
000037e5 000037f1 d
_strcpy
000037e5 0 none ,g *
FILE=toupper
000037f2 000037ff e
_toupper
000037f2 0 none ,g *
FILE=_REL_f_inf
00003800 00003807 8
__REL_f_inf
00003800 0 none ,g *
FILE=_REL_f_norm
00003808 00003817 10
__REL_f_norm
00003808 0 none ,g *
FILE=_REL_f_round
00003818 0000382a 13
__REL_f_round
00003818 0 none ,g *
FILE=_REL_ftol
0000382b 0000385f 35
__REL_ftol
0000382b 0 none ,g *
FILE=_REL_ltof
00003860 000038a9 4a
__REL_ltof
00003860 0 none ,g *
FILE=_REL_print
000038aa 00005801 1f58
__REL_print
000038aa 1046 func ,g *
__REL_fltprn@1
000048f0 941 func ,l *
__REL_henkan1@1
00005231 28 func ,l *
__REL_henkan2@1
00005259 33 func ,l *
__REL_pri@1
0000528c 298 func ,l *
__REL_fltgeti@1
00005524 19d func ,l *
__REL_inmod@1
000056c1 141 func ,l *
FILE=_COM_feq
00005802 00005817 16
__COM_feq
00005802 0 none ,g *
FILE=_COM_fge
00005818 0000582d 16
__COM_fge
00005818 0 none ,g *
FILE=_COM_flt
0000582e 00005843 16
__COM_flt
0000582e 0 none ,g *
FILE=_COM_fne
00005844 00005854 11
__COM_fne
00005844 0 none ,g *
FILE=_COM_ftosl
00005855 0000585c 8
__COM_ftosl
00005855 0 none ,g *
FILE=_COM_lshr
0000585d 0000587d 21
__COM_lshr
00005867 0 none ,g *
FILE=_COM_sidiv
0000587e 0000589f 22
__COM_sidiv
00005880 0 none ,g *
FILE=_COM_sirem
000058a0 000058bf 20
__COM_sirem
000058a0 0 none ,g *
FILE=_COM_ulldiv
000058c0 000058e9 2a
__COM_ulldiv
000058c0 0 none ,g *
FILE=_COM_ullrem
000058ea 0000591a 31
__COM_ullrem
000058ea 0 none ,g *
FILE=_REL_fcmp
0000591b 00005952 38
__REL_fcmp
0000591b 0 none ,g *
FILE=_REL_fordered_core
00005953 0000596e 1c
__REL_fordered_core
00005953 0 none ,g *
FILE=_REL_lldiv
0000596f 00005b74 206
__REL_lldiv
0000598b 0 none ,g *
FILE=_REL_llrem
00005b75 00005d78 204
__REL_llrem
00005b92 0 none ,g *
FILE=_REL_ltosl
00005d79 00005d9d 25
__REL_ltosl
00005d79 0 none ,g *
SECTION=.bss
FILE=DefaultBuild\r_cg_serial.obj
000faf00 000faf1f 20
_gp_uart0_tx_address
000faf00 2 data ,g *
_g_uart0_tx_count
000faf02 2 data ,g *
_gp_uart0_rx_address
000faf04 2 data ,g *
_g_uart0_rx_count
000faf06 2 data ,g *
_g_uart0_rx_length
000faf08 2 data ,g *
_gp_uart1_tx_address
000faf0a 2 data ,g *
_g_uart1_tx_count
000faf0c 2 data ,g *
_gp_uart1_rx_address
000faf0e 2 data ,g *
_g_uart1_rx_count
000faf10 2 data ,g *
_g_uart1_rx_length
000faf12 2 data ,g *
_g_iica0_master_status_flag
000faf14 1 data ,g *
_g_iica0_slave_status_flag
000faf15 1 data ,g *
_gp_iica0_rx_address
000faf16 2 data ,g *
_g_iica0_rx_len
000faf18 2 data ,g *
_g_iica0_rx_cnt
000faf1a 2 data ,g *
_gp_iica0_tx_address
000faf1c 2 data ,g *
_g_iica0_tx_cnt
000faf1e 2 data ,g *
FILE=sprintf
000faf20 000faf23 4
__REL_pointer@1
000faf20 4 data ,l *
FILE=_REL_print
000faf24 000fafa3 80
_qt@1@_REL_inmod@1
000faf24 80 data ,l *
SECTION=.dataR
FILE=DefaultBuild\r_main.obj
000fafa4 000fb008 65
_uart_rx_done
000fafa4 1 data ,g *
_uart_rx_index
000fafa5 1 data ,g *
_uart_rx_buffer
000fafa6 60 data ,g *
_uart_rx_length
000fb006 2 data ,g *
_g_fixed_addr@1
000fb008 1 data ,l *
FILE=DefaultBuild\i2c.obj
000fb00a 000fb00f 6
_g_i2c_last_command
000fb00a 3 data ,g *
_g_i2c_command_valid
000fb00d 1 data ,g *
_dis@1@disable
000fb00e 2 data ,l *
FILE=DefaultBuild\uart.obj
000fb010 000fb020 11
_g_adc_bytes
000fb010 10 data ,g *
_g_adc_len
000fb020 1 data ,g *
Absolute value symbols
FILE=rlink_generates_04
__s.text
0000014b 0 none ,g *
__e.text
000002fe 0 none ,g *
__s.textf
000002fe 0 none ,g *
__e.textf
00001cf1 0 none ,g *
__s.const
00003000 0 none ,g *
__e.const
0000335c 0 none ,g *
__s.constf
00000080 0 none ,g *
__e.constf
00000094 0 none ,g *
__s.data
000000ce 0 none ,g *
__e.data
0000014b 0 none ,g *
__s.sdata
00000080 0 none ,g *
__e.sdata
00000080 0 none ,g *
__s.bss
000faf00 0 none ,g *
__e.bss
000fafa4 0 none ,g *
__s.sbss
000ffe20 0 none ,g *
__e.sbss
000ffe20 0 none ,g *
__s.dataR
000fafa4 0 none ,g *
__e.dataR
000fb021 0 none ,g *
__s.sdataR
000ffe20 0 none ,g *
__e.sdataR
000ffe20 0 none ,g *
__s.init_array
00000094 0 none ,g *
__e.init_array
00000094 0 none ,g *
__s.RLIB
000000c4 0 none ,g *
__e.RLIB
000000c4 0 none ,g *
__s.SLIB
0000335c 0 none ,g *
__e.SLIB
00005d9e 0 none ,g *
__s.option_byte
000000c0 0 none ,g *
__e.option_byte
000000c4 0 none ,g *
__s.security_id
000000c4 0 none ,g *
__e.security_id
000000ce 0 none ,g *
__s.vect
00000000 0 none ,g *
__e.vect
00000080 0 none ,g *
__RAM_ADDR_START
000faf00 0 none ,g *
__RAM_ADDR_END
000ffee0 0 none ,g *
__STACK_ADDR_START
000ffe20 0 none ,g *
__STACK_ADDR_END
000fb022 0 none ,g *
*** Unfilled Areas ***
AREA START END
*** Delete Symbols ***
SYMBOL SIZE INFO

1267
DefaultBuild/multical.mot

File diff suppressed because it is too large

BIN
DefaultBuild/owi.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_adc.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_adc_user.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_cgc.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_cgc_user.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_port.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_port_user.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_serial.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_serial_user.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_wdt.obj

Binary file not shown.

BIN
DefaultBuild/r_cg_wdt_user.obj

Binary file not shown.

BIN
DefaultBuild/r_main.obj

Binary file not shown.

BIN
DefaultBuild/r_systeminit.obj

Binary file not shown.

BIN
DefaultBuild/stkinit.obj

Binary file not shown.

BIN
DefaultBuild/uart.obj

Binary file not shown.

298
QualityReport(multical,DefaultBuild).txt

@ -0,0 +1,298 @@
QualityReport
2026년 1월 14일 수요일 오전 10:30:44
------ Start build(multical, DefaultBuild) ------
C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RL\V1.15.00\Bin\ccrl.exe r_main.c -cpu=S3 -o DefaultBuild\r_main.obj "-dev=C:\Program Files (x86)\Renesas Electronics\CS+\CC\Device\RL78\Devicefile\DR5F10PPJ.DVF" -g -g_line -I "..\..\Documents\카카오톡 받은 파일\IDH1.1\IDH1.1" -I ..\IDH1.1 -I . -c -msg_lang=english
C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RL\V1.15.00\Bin\ccrl.exe dipSwitch.c -cpu=S3 -o DefaultBuild\dipSwitch.obj "-dev=C:\Program Files (x86)\Renesas Electronics\CS+\CC\Device\RL78\Devicefile\DR5F10PPJ.DVF" -g -g_line -I "..\..\Documents\카카오톡 받은 파일\IDH1.1\IDH1.1" -I ..\IDH1.1 -I . -c -msg_lang=english
W0511106:The folder "..\..\Documents\카카오톡 받은 파일\IDH1.1\IDH1.1" specified by the "-I" option is not found.
W0511106:The folder "..\..\Documents\카카오톡 받은 파일\IDH1.1\IDH1.1" specified by the "-I" option is not found.
W0511106:The folder "..\IDH1.1" specified by the "-I" option is not found.
W0511106:The folder "..\IDH1.1" specified by the "-I" option is not found.
W0511186:The evaluation period for the option "-Odefault" of CC-RL V1 is valid for the remaining 60 days. After that, it will be implicitly changed to "-Olite". Please consider purchasing the product to continue using "-Odefault".
W0511186:The evaluation period for the option "-Odefault" of CC-RL V1 is valid for the remaining 60 days. After that, it will be implicitly changed to "-Olite". Please consider purchasing the product to continue using "-Odefault".
owi.h(47):W0523076:Function declarations should have prototype
i2c.h(8):W0520047:Incompatible redefinition of macro "RAM_BYTES" (declared at line 11 of "uart.h")
C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RL\V1.15.00\inc\stdint.h(18):W0520301:Typedef name has already been declared (with same type)
C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RL\V1.15.00\inc\stdint.h(19):W0520301:Typedef name has already been declared (with same type)
C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RL\V1.15.00\inc\stdint.h(20):W0520301:Typedef name has already been declared (with same type)
C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RL\V1.15.00\inc\stdint.h(25):W0520301:Typedef name has already been declared (with same type)
C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RL\V1.15.00\inc\stdint.h(26):W0520301:Typedef name has already been declared (with same type)
C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RL\V1.15.00\inc\stdint.h(27):W0520301:Typedef name has already been declared (with same type)
r_main.c(115):W0520172:External/internal linkage conflict with previous declaration
r_main.c(133):W0523077:Called function should have prototype
C:\Program Files (x86)\Renesas Electronics\CS+\CC\CC-RL\V1.15.00\Bin\rlink.exe -subcommand=DefaultBuild\multical.clnk
W0561018:The evaluation period of CC-RL V1 is valid for the remaining 60 days. After that, functional limit will be applied. Please consider purchasing the product.
W0561018:The evaluation period of CC-RL V1 is valid for the remaining 60 days. After that, functional limit will be applied. Please consider purchasing the product.
Renesas Optimizing Linker Completed
------ Build ended(Error:0, Warning:18)(multical, DefaultBuild) ------
--- CommandFile 1 ---
DefaultBuild\multical.clnk :
-Input=DefaultBuild\cstart.obj
-Input=DefaultBuild\stkinit.obj
-Input=DefaultBuild\r_main.obj
-Input=DefaultBuild\r_systeminit.obj
-Input=DefaultBuild\r_cg_cgc.obj
-Input=DefaultBuild\r_cg_cgc_user.obj
-Input=DefaultBuild\r_cg_serial.obj
-Input=DefaultBuild\r_cg_serial_user.obj
-Input=DefaultBuild\r_cg_wdt.obj
-Input=DefaultBuild\r_cg_wdt_user.obj
-Input=DefaultBuild\r_cg_adc.obj
-Input=DefaultBuild\r_cg_adc_user.obj
-Input=DefaultBuild\r_cg_port.obj
-Input=DefaultBuild\r_cg_port_user.obj
-Input=DefaultBuild\anaout.obj
-Input=DefaultBuild\owi.obj
-Input=DefaultBuild\i2c.obj
-Input=DefaultBuild\uart.obj
-Input=DefaultBuild\delay.obj
-Input=DefaultBuild\dipSwitch.obj
-SECURITY_ID=00000000000000000000
-DEVICE=C:\Program Files (x86)\Renesas Electronics\CS+\CC\Device\RL78\Devicefile\DR5F10PPJ.DVF
-DEBug
-NOCOmpress
-NOOPtimize
-OUtput=DefaultBuild\multical.abs
-OCDBG=04
-USER_OPT_BYTE=FFFFF8
-LISt=DefaultBuild\multical.map
-SHow=SYmbol,Total_size
-AUTO_SECTION_LAYOUT
-ROm=.data=.dataR
-ROm=.sdata=.sdataR
-NOMessage
-MEMory=High
-NOLOgo
-LIBrary=DefaultBuild\multical.lib
-end
-Input=DefaultBuild\multical.abs
-DEVICE=C:\Program Files (x86)\Renesas Electronics\CS+\CC\Device\RL78\Devicefile\DR5F10PPJ.DVF
-OUtput=DefaultBuild\multical.mot
-FOrm=Stype
-NOMessage
-exit
--- SHA1 hash value of output files ---
C:\Users\COMPUTER1\OneDrive\문서\카카오톡 받은 파일\Amosense_Firmware\Amosense_Firmware\DefaultBuild\multical.abs: 02573826f641eca7df73ff054c8e823c4d5b11c4
C:\Users\COMPUTER1\OneDrive\문서\카카오톡 받은 파일\Amosense_Firmware\Amosense_Firmware\DefaultBuild\multical.mot: c95d0bc8130fb9e402da42eee0be70f0ce6eca3e
--- System Information ---
*OS Version
Microsoft Windows 11 Pro (-, 10.0.26200, WOW64)
*Language
한국어(대한민국)
*.NET Framework Version
Microsoft .NET Framework 4 [.NET 4.8 or later] (533509)
*WebView2 Version
143.0.3650.139
--- Application Information ---
*Product Name
CS+ for CC
*Package Version
V8.13.00 [05 Dec 2024]
*Version
V9.13.00.05 [12 Nov 2024]
*Assembly Version
3.12.10.1
*Product License
*Execution Place
C:\Program Files (x86)\Renesas Electronics\CS+\CC
*Memory Usage
*Private Working Set
295 MB
*Number of GDI Objects
2228
*Number of USER Objects
1638
*Opened Files
3 editors, 3 files, 16 KB
--- Build Tool Plug-in Information ---
RH850 Build tool CC-RH Plug-in
*Version
V8.09.00.00 [07 Oct 2022]
*Assembly Version
1.1.10.12
*DLL File Name
BuildToolCCRH.dll
RL78 Build tool CC-RL Plug-in
*Version
V8.11.00.00 [29 Sep 2023]
*Assembly Version
1.0.0.0
*DLL File Name
BuildToolCCRL.dll
RX Build tool CC-RX Plug-in
*Version
V8.09.00.00 [07 Oct 2022]
*Assembly Version
3.12.10.1
*DLL File Name
BuildToolCCRX.dll
RH850 Build tool GHS CCRH850 Plug-in
*Version
V1.10.00.01 [25 Sep 2024]
*Assembly Version
1.0.0.0
*DLL File Name
BuildToolGHSCCRH850.dll
--- Debug Tool Plug-in Information ---
Debugger Collection Plug-in
*Version
V8.13.00.04 [26 Nov 2024]
*Assembly Version
2.12.10.1
*DLL File Name
DebugToolCollection.dll
--- Other Plug-in Information ---
Code Generator Plug-in for RH850
*Version
V1.02.02.05 [25 May 2018]
*Assembly Version
1.0.0.0
*DLL File Name
CodeGeneratorRH850.dll
Code Generator Plug-in
*Version
V4.08.06.01 [28 Oct 2022]
*Assembly Version
3.0.0.0
*DLL File Name
CodePart.dll
Code Generator/PinView Plug-in
*Version
V2.10.07.02 [08 Nov 2021]
*Assembly Version
1.0.0.0
*DLL File Name
CodePart2.dll
Debug Console Plug-in
*Version
V8.09.00.03 [24 Nov 2022]
*Assembly Version
8.9.0.0
*DLL File Name
DebugConsole.dll
Quick and Effective tool solution - QE
*Version
V9.12.00.01 [08 Apr 2024]
*Assembly Version
1.15.10.16
*DLL File Name
InCarTools.dll
Pin Configurator Plug-in
*Version
V1.54.01.01 [31 Jul 2014]
*Assembly Version
1.6.10.23
*DLL File Name
PinConfig.dll
Program Analyzer Plug-in
*Version
V4.13.00.03 [24 May 2023]
*Assembly Version
3.12.11.9
*DLL File Name
ProgramAnalyzer.dll
IronPython Console Plug-in
*Version
V1.49.00.02 [08 Nov 2024]
*Assembly Version
1.6.10.23
*DLL File Name
PythonConsole.dll
Editor plug-in DLL
*Version
V1.20.00.03 [20 May 2024]
*Assembly Version
1.1.0.0
*DLL File Name
SEditor.dll
Stack Usage Tracer
*Version
V1.05.00.02 [30 Jul 2014]
*Assembly Version
1.30.11.15
*DLL File Name
Stk.dll
Update Manager Plug-in
*Version
V2.03.00.02 [29 Oct 2018]
*Assembly Version
1.13.6.20
*DLL File Name
Update.dll
Debug Tool Common Interface
*Version
V8.13.00.04 [26 Nov 2024]
*Assembly Version
3.12.10.1
*DLL File Name
CommonDebuggerInterface.dll
Device Information Common Interface
*Version
V9.13.00.02 [03 Oct 2024]
*Assembly Version
3.0.0.0
*DLL File Name
DeviceInformation.dll
--- Main Project Information ---
C:\Users\COMPUTER1\OneDrive\문서\카카오톡 받은 파일\Amosense_Firmware\Amosense_Firmware\multical.mtpj
Microcontroller Information
*R5F10PPJ
*File Name: Version
RL78_Productlist.xml: V8.130000
R5F10PPJ_common.xml: V1.13.00.XX.02
DR5F10PPJ.DVF: V1.11
f14_ppx.ti: V1.02
-: -
Build Tool Information
*CC-RL
* Version of plug-in(*.dll)
V8.13.00.02 [09 Oct 2024]
* The Version of the Compiler Package
V1.15.00
* The version of SMS Assembler
V1.00.00.01 [29 May 2020]
* The version of GREEN_DSP Structured Assembler
V1.05.00
Debug Tool Information
*RL78 Simulator
Debugger Library V8.13.00.04 [26 Nov 2024]
Other Tool Information
*None
*None
*None
*Pin Configurator
*Program Analyzer
*Version
V4.13.00.03 [24 May 2023]
*Code Generator
Other Information
*RL78/F14 Code Library
*Version
V2.03.07.02 [08 Nov 2021]
*Description
Code library for RL78/F14 code generation plugin.

110
anaout.c

@ -0,0 +1,110 @@
#include "anaout.h"
// -------------------------------------------------------
// Helper macros
// -------------------------------------------------------
#define BIT(n) (1u << (n))
// -------------------------------------------------------
// ANAOUT mapping (사용자 제공 기준)
// ANAOUT_1 : P64 -> P6.4
// ANAOUT_2 : P65 -> P6.5
// ANAOUT_3 : P66 -> P6.6
// ANAOUT_4 : P67 -> P6.7
//
// ANAOUT_5 : P44 -> P4.4
// ANAOUT_6 : P43 -> P4.3
// ANAOUT_7 : P42 -> P4.2
// ANAOUT_8 : P41 -> P4.1
//
// ANAOUT_9 : P50 -> P5.0
// ANAOUT_10 : P51 -> P5.1
// ANAOUT_11 : P52 -> P5.2
//
// ANAOUT_12 : P60 -> P6.0
// ANAOUT_13 : P61 -> P6.1
//
// ANAOUT_14 : P72 -> P7.2
// ANAOUT_15 : P73 -> P7.3
// ANAOUT_16 : P75 -> P7.5
// ANAOUT_17 : P74 -> P7.4
// ANAOUT_18 : P76 -> P7.6
// ANAOUT_19 : P77 -> P7.7
//
// ANAOUT_20 : P130 -> P13.0
// -------------------------------------------------------
// 그룹별 마스크(빠른 AllLow/Init용)
#define P4_ANA_MASK (BIT(4) | BIT(3) | BIT(2) | BIT(1)) // P4.4~P4.1
#define P5_ANA_MASK (BIT(0) | BIT(1) | BIT(2)) // P5.0~P5.2
#define P6_ANA_MASK (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(1) | BIT(0)) // P6.7~P6.4 + P6.1~P6.0
#define P7_ANA_MASK (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | BIT(2)) // P7.7~P7.2
#define P13_ANA_MASK (BIT(0)) // P13.0
void ANAOUT_AllLow(void)
{
// 해당 비트만 LOW로 내림
P4 &= (uint8_t)~(uint8_t)P4_ANA_MASK;
P5 &= (uint8_t)~(uint8_t)P5_ANA_MASK;
P6 &= (uint8_t)~(uint8_t)P6_ANA_MASK;
P7 &= (uint8_t)~(uint8_t)P7_ANA_MASK;
P13 &= (uint8_t)~(uint8_t)P13_ANA_MASK;
}
void ANAOUT_Init(void)
{
// 출력 설정: PM bit = 0 이 출력
PM4 &= (uint8_t)~(uint8_t)P4_ANA_MASK;
PM5 &= (uint8_t)~(uint8_t)P5_ANA_MASK;
PM6 &= (uint8_t)~(uint8_t)P6_ANA_MASK;
PM7 &= (uint8_t)~(uint8_t)P7_ANA_MASK;
// 초기 상태: 전부 LOW
ANAOUT_AllLow();
}
void ANAOUT_Select(uint8_t ch)
{
if (ch < ANAOUT_CH_MIN || ch > ANAOUT_CH_MAX) {
ANAOUT_AllLow();
return;
}
ANAOUT_AllLow();
__nop(); __nop(); __nop(); __nop(); // break-before-make
// 2) 선택된 채널만 HIGH
switch (ch)
{
case 1: P6 |= (uint8_t)BIT(4); break; // P64
case 2: P6 |= (uint8_t)BIT(5); break; // P65
case 3: P6 |= (uint8_t)BIT(6); break; // P66
case 4: P6 |= (uint8_t)BIT(7); break; // P67
case 5: P4 |= (uint8_t)BIT(4); break; // P44
case 6: P4 |= (uint8_t)BIT(3); break; // P43
case 7: P4 |= (uint8_t)BIT(2); break; // P42
case 8: P4 |= (uint8_t)BIT(1); break; // P41
case 9: P5 |= (uint8_t)BIT(0); break; // P50
case 10: P5 |= (uint8_t)BIT(1); break; // P51
case 11: P5 |= (uint8_t)BIT(2); break; // P52
case 12: P6 |= (uint8_t)BIT(0); break; // P60
case 13: P6 |= (uint8_t)BIT(1); break; // P61
case 14: P7 |= (uint8_t)BIT(2); break; // P72
case 15: P7 |= (uint8_t)BIT(3); break; // P73
case 16: P7 |= (uint8_t)BIT(5); break; // P75
case 17: P7 |= (uint8_t)BIT(4); break; // P74
case 18: P7 |= (uint8_t)BIT(6); break; // P76
case 19: P7 |= (uint8_t)BIT(7); break; // P77
case 20: P13 |= (uint8_t)BIT(0); break; // P130
default:
// 범위 밖이면 전체 LOW 유지
break;
}
}

15
anaout.h

@ -0,0 +1,15 @@
#ifndef ANAOUT_H
#define ANAOUT_H
#include "r_cg_macrodriver.h"
#include "r_cg_port.h"
#include <stdint.h>
#define ANAOUT_CH_MIN (1u)
#define ANAOUT_CH_MAX (20u)
void ANAOUT_Init(void);
void ANAOUT_AllLow(void);
void ANAOUT_Select(uint8_t ch); // 1~20, 범위 밖이면 AllLow 처리
#endif

4
common.h

@ -0,0 +1,4 @@
#include "delay.h"
#include "uart.h"
#include "owi.h"
#include "i2c.h"

86
delay.c

@ -0,0 +1,86 @@
#include "delay.h"
/**
* : delay
* : (delay)
*
* :
* - d : .
*
* :
* - while(d--) CPU를
* -
* - CPU
*
* :
* - CPU
* -
*/
void delay(long d){
while(d--);
}
/**
* : delay_us
* : (us) (delay)
*
* :
* - us : ( )
*
* :
* 1. us count
* - us <= 150 : count = (us * 100 + 50) / 100
* - us > 150 : count = (us * 106 + 50) / 100
* - +50
* 2. for count만큼 __nop()
* - __nop() "No Operation" , CPU
* 3.
*
* :
* - CPU
* -
*/
void delay_us(volatile uint32_t us)
{
volatile uint32_t i;
volatile uint32_t count;
if (us <= 150) {
count = (us * 100 + 50) / 100; // 소수점 올림 효과를 위해 +50 추가
} else {
count = (us * 106 + 50) / 100;
}
for (i = 0; i < count; i++) {
__nop();
}
}
/**
* : delay_ms
* : (ms) (delay)
*
* :
* - ms : ( )
*
* :
* 1. for (i) ms만큼
* 2. for (j) 0~799
* - 800 CPU
* - CPU
* 3.
*
* :
* - (CPU , )
* -
* - delay_ms와 delay_us를
*/
void delay_ms(unsigned int ms)
{
volatile unsigned int i, j;
for (i = 0; i < ms; i++)
for (j = 0; j < 800; j++); // 내부 루프 조정 필요 (클럭에 따라 조정)
}

5
delay.h

@ -0,0 +1,5 @@
#include "r_cg_macrodriver.h"
void delay(long d);
void delay_ms(unsigned int ms);
void delay_us(volatile uint32_t us);

35
dipSwitch.c

@ -0,0 +1,35 @@
#include "dipSwitch.h"
/*
* :
* ADD_1..ADD_5 = P8.1..P8.5
* Pull-up to VCC5, DIP ON -> GND(LOW) => Active-Low
*/
#define DIP_PORT P8
#define DIP_PM PM8
#define DIP_MASK (0x3Eu) // b0011_1110 = P8.1~P8.5
#define DIP_SHIFT (1u) // P8.1이 bit0로 오도록
void DipSwitch_Init(void)
{
// 입력 설정: PM bit=1 => input
DIP_PM |= DIP_MASK;
}
uint8_t DipSwitch_ReadValue_0to31(void)
{
uint8_t raw = (uint8_t)(DIP_PORT & DIP_MASK);
// Active-Low이므로 반전 후, 마스크 적용
uint8_t v = (uint8_t)((~raw) & DIP_MASK);
// P8.1~P8.5 -> bit0~bit4
v = (uint8_t)(v >> DIP_SHIFT);
return (uint8_t)(v & 0x1Fu); // 0~31
}
uint8_t DipSwitch_ReadAddr_1to32(void)
{
return (uint8_t)(DipSwitch_ReadValue_0to31() + 1u); // 1~32
}

33
dipSwitch.h

@ -0,0 +1,33 @@
#ifndef DIPSWITCH_H
#define DIPSWITCH_H
#include "r_cg_macrodriver.h"
#include "r_cg_port.h" // P8, PM8 사용
#ifdef __cplusplus
extern "C" {
#endif
/**
* DIP Switch ( )
*/
void DipSwitch_Init(void);
/**
* DIP Switch(5bit) (1~32)
* - : Pull-up, DIP ON -> GND (Active-Low)
* - : P8.1~P8.5 (ADD_1~ADD_5)
*/
uint8_t DipSwitch_ReadAddr_1to32(void);
/**
* () : DIP 5bit(0~31)
* - ADD_1이 LSB
*/
uint8_t DipSwitch_ReadValue_0to31(void);
#ifdef __cplusplus
}
#endif
#endif /* DIPSWITCH_H */

487
i2c.c

@ -0,0 +1,487 @@
#include "i2c.h"
#include "delay.h"
#include "uart.h"
#include <string.h>
uint8_t g_i2c_last_command[3] = {0};
uint8_t g_i2c_command_valid = 0;
/**
* : disable
* : I2C (disable)
*
* :
*
* : (void)
*
* :
* 1)
* - dis {0x01, 0x02}
*
* 2) I2C
* - R_IICA0_Master_Send()
* -
* - UART로 "I2C Send Failed"
*
* :
* - SLAVE_ADDR는 I2C
* - sizeof(dis)
* - 100ms
*/
void disable(void){
static uint8_t dis[] = {0x01, 0x02};
//static uint8_t tx[] = {0xT0, 0x00, 0x00};
// I2C 마스터 송신
if (R_IICA0_Master_Send(SLAVE_ADDR << 1, dis, sizeof(dis), 100) != MD_OK)
{
uart_send_string("I2C Send Failed\r\n");
return;
}
}
/**
* : I2C_EnablePower
* : I2C .
*
* :
*
* : (void)
*
* :
* 1) P7 HIGH
* - _02_Pn1_OUTPUT_1 : P7 1 HIGH
*
* :
* - I2C
* - HIGH
*/
void I2C_EnablePower(void) {
P7 = _02_Pn1_OUTPUT_1;
}
/**
* : I2C_DisablePower
* : I2C .
*
* :
*
* : (void)
*
* :
* 1) P7 LOW
* - _00_Pn1_OUTPUT_0 : P7 1 LOW
*
* :
* - I2C
* - LOW
*/
void I2C_DisablePower(void) {
P7 = _00_Pn1_OUTPUT_0;
}
/**
* : I2C_A_Command_Mode_receiveData
* : I2C ADC ,
* UART로 .
*
* :
* - tx_data : (UserCmd)
* - tx_len :
* - id : I2C
*
* : (void)
*
* :
* 1) ADC
* - ADC_ReadAndSend_UART() 4 ADC
* - 4 UART
* - TOP, BRP, BRN, BRP-BRN, BOT UART
*
* 2) CMD_LIST I2C
* - CMD_LIST는 6
* - R_IICA0_Master_Send()
* - R_IICA0_Master_Receive()
* - (rx[1], rx[2]) UART
*
* 3) CMD
* - tx_data와 tx_len이 I2C
* - rx UART
* - "0000"
*
* 4)
* - (line) UART로
* - delay로
*
* :
* - RAM_BYTES는 I2C
* - UART "," , CRLF
* - ADC와 I2C
*/
void I2C_A_Command_Mode_receiveData(const uint8_t *tx_data, uint8_t tx_len,uint8_t id )
{
uint8_t CMD_LIST[6][3] = {
{0x2E, 0x00, 0x00}, // BR
{0x2E, 0x01, 0x00}, // BR_AZ
{0x2E, 0x02, 0x00}, // T_RAW
{0x2E, 0x16, 0x00}, // Y_data
{0x2E, 0x41, 0x00}, // BR_AOUT
{0x2E, 0x40, 0x00}
};
char line[128];
size_t n = 0;
uint8_t rx[RAM_BYTES] = {0};
int j;
// 1) ADC 읽기 (4채널)
ADC_ReadAndSend_UART();
if (g_adc_len != 4) { // TOP, BRP, BRN, BOT만 읽음
uart_send_string("Err:adc_count\r\n");
return;
}
// 2) UART 문자열 구성 (5개 값)
for (j = 0; j < 5; j++) {
float v = 0.0f;
switch (j) {
case 0: // 1번: TOP
v = g_adc_bytes[0];
break;
case 1: // 2번: BRP
v = g_adc_bytes[1];
break;
case 2: // 3번: BRN
v = g_adc_bytes[2];
break;
case 3: // 4번: BRP - BRN
v = g_adc_bytes[1] - g_adc_bytes[2];
break;
case 4: // 5번: BOT
v = g_adc_bytes[3];
break;
}
n += sprintf(&line[n], "%.2f", v);
line[n++] = ',';
}
delay(100000);
// 2) CMD_LIST 순서대로 I2C 읽기
for (j = 0; j < 6; j++) {
if (R_IICA0_Master_Send((id << 1), CMD_LIST[j], 3, 100) != MD_OK) {
uart_send_string("I2C Send Failed\r\n");
return;
}
delay(10000);
if (R_IICA0_Master_Receive((id << 1), rx, RAM_BYTES, 100) != MD_OK) {
uart_send_string("I2C Receive Failed\r\n");
return;
}
delay(10000);
n += sprintf(&line[n], "%02X%02X", rx[1], rx[2]);
// 마지막 CMD 뒤에는 쉼표 붙이지 않음
if (j < 5) {
line[n++] = ',';
}
}
// 3) UserCmd 처리
line[n++] = ','; // UserCmd 앞 쉼표
if (tx_data != NULL && tx_len > 0) {
if (R_IICA0_Master_Send((id << 1), tx_data, tx_len, 100) != MD_OK) {
uart_send_string("I2C UserCmd Send Failed\r\n");
return;
}
delay(100000);
if (R_IICA0_Master_Receive((id << 1), rx, RAM_BYTES, 100) != MD_OK) {
uart_send_string("I2C UserCmd Receive Failed\r\n");
return;
}
delay(10000);
n += sprintf(&line[n], "%02X%02X", rx[1], rx[2]);
} else {
n += sprintf(&line[n], "0000");
}
// 마지막에 CRLF
line[n++] = '\r';
line[n++] = '\n';
line[n] = '\0';
uart_send_string(line);
delay(10000);
}
/**
* : I2C_Diagnostic
* : I2C UART로
*
* :
* - id : I2C
*
* : (void)
*
* :
* 1) CMD_LIST
* - 10
* - 3: { , 1, 2}
*
* 2) CMD_LIST I2C
* - R_IICA0_Master_Send()
* - R_IICA0_Master_Receive()
* - (rx[1], rx[2]) UART (line)
* - CMD
* - / delay로
*
* 3) UART
* - (line) UART로
* - CRLF
*
* :
* - RAM_BYTES는 I2C
* - UART CMD별 2 HEX로
* - I2C
*/
void I2C_Diagnostic(uint8_t id )
{
uint8_t CMD_LIST[10][3] = {
{0x2E, 0x01, 0x00}, // BR
{0x2E, 0x00, 0x00}, // BR_AZ
{0x2E, 0x02, 0x00}, // T_RAW
{0x2E, 0x03, 0x00}, // Y_data
{0x2E, 0x21, 0x00}, // BR_AOUT
{0x2E, 0x40, 0x00},
{0x2E, 0x05, 0x00},
{0x2E, 0x07, 0x00},
{0x2E, 0x19, 0x00},
{0x2E, 0x0B, 0x00}
};
char line[128];
size_t n = 0;
uint8_t rx[RAM_BYTES] = {0};
int j;
// 2) CMD_LIST 순서대로 I2C 읽기
for (j = 0; j < 10; j++) {
if (R_IICA0_Master_Send((id << 1), CMD_LIST[j], 3, 100) != MD_OK) {
uart_send_string("I2C Send Failed\r\n");
return;
}
delay(10000);
if (R_IICA0_Master_Receive((id << 1), rx, RAM_BYTES, 100) != MD_OK) {
uart_send_string("I2C Receive Failed\r\n");
return;
}
delay(10000);
n += sprintf(&line[n], "%02X%02X", rx[1], rx[2]);
// 마지막 CMD 뒤에는 쉼표 붙이지 않음
if (j < 9) {
line[n++] = ',';
}
}
// 마지막에 CRLF
line[n++] = '\r';
line[n++] = '\n';
line[n] = '\0';
uart_send_string(line);
delay(10000);
}
/**
* : I2C_T_Command_Mode_receiveData
* : I2C (tx_data) , UART로
*
* :
* - tx_data : I2C로
* - tx_len : ()
* - id : I2C
*
* : (void)
*
* :
* 1) I2C
* - R_IICA0_Create() I2C
* - I2C (I2C_EnablePower())
* - delay(1)
*
* 2) I2C
* - R_IICA0_Master_Send() tx_data
* - UART로 "I2C Send Failed"
*
* 3) UART
* - "51" UART로
*
* :
* - (read)
* - UART "51" /
*/
void I2C_T_Command_Mode_receiveData(const uint8_t *tx_data, uint8_t tx_len,uint8_t id )
{
char uart_buf[16];
int j;
uint8_t rx[3] = {0};
R_IICA0_Create();
I2C_EnablePower();
delay(1000000);
if (R_IICA0_Master_Send((id << 1), tx_data, tx_len, 100) != MD_OK)
{
uart_send_string("I2C Send Failed\r\n");
return;
}
uart_send_string("51\r\n");
}
/**
* : I2C_Command_Mode_receiveData
* : I2C (tx_data) , UART로
*
* :
* - tx_data : I2C로
* - tx_len : ()
* - id : I2C
*
* : (void)
*
* :
* 1) I2C
* - R_IICA0_Master_Send() (id) tx_data
* - UART로 "I2C Send Failed"
*
* 2) UART
* - "51" UART로
* -
*
* :
* -
* - I2C
*/
void I2C_Command_Mode_receiveData(const uint8_t *tx_data, uint8_t tx_len,uint8_t id )
{
char uart_buf[16];
int j;
uint8_t rx[3] = {0};
if (R_IICA0_Master_Send((id << 1), tx_data, tx_len, 100) != MD_OK)
{
uart_send_string("I2C Send Failed\r\n");
return;
}
uart_send_string("51\r\n");
}
/**
* : I2C_Command_Mode_Send
* : I2C , UART로
*
* :
* - tx_len : ()
* - id : I2C
*
* : (void)
*
* :
* 1) I2C
* - R_IICA0_Master_Receive() (id) tx_len
* - UART로 "I2C Receive Failed"
*
* 2) UART
* - "%02X "
* - 2 "%02X%02X "
* - 1 "%02X"
* - ("\r\n")
*
* 3) delay
* - delay를 UART
*
* :
* - I2C
* -
*/
void I2C_Command_Mode_Send(uint8_t tx_len, uint8_t id)
{
char uart_buf[16];
char tmp_buf[8];
int i,j;
uint8_t rx[600];
uint8_t va0, va1;
uint8_t status = 0x00;
int tries = 0;
/* ★추가: 버퍼 초기화 (기존 로직/출력 형식 유지) */
memset(uart_buf, 0, sizeof(uart_buf));
memset(tmp_buf, 0, sizeof(tmp_buf));
memset(rx, 0x00, sizeof(rx)); // 가드 패턴(0x00으로 해도 무방)
if (R_IICA0_Master_Receive((id << 1), rx, (uint8_t)(tx_len), 1000) != MD_OK) {
uart_send_string("I2C Receive Failed\r\n");
return;
}
delay(1000000);
sprintf(uart_buf, "%02X ", rx[0]);
strcpy(tmp_buf, uart_buf);
uart_send_string(uart_buf);
delay(10000);
for (i = 1; i < (tx_len); i += 2) {
va0 = rx[i];
if (i + 1 < (tx_len)) {
va1 = rx[i + 1];
delay(10000);
sprintf(uart_buf, "%02X%02X ", va0, va1);
uart_send_string(uart_buf);
delay(10000);
} else {
delay(10000);
sprintf(uart_buf, "%02X", va0);
strcpy(tmp_buf, uart_buf);
uart_send_string(uart_buf);
delay(10000);
}
}
uart_send_string("\r\n");
}

30
i2c.h

@ -0,0 +1,30 @@
#include "r_cg_macrodriver.h"
#include "r_cg_serial.h"
#include "r_cg_port.h"
#include "uart.h"
#define SLAVE_ADDR 0x28
#define RAM_BYTES 12
extern volatile uint8_t i2c_tx_done;
extern volatile uint8_t i2c_rx_done;
void I2C_EnablePower(void);
void I2C_DisablePower(void);
void I2C_Command_Mode(void);
//void I2C_read_nvm(void);
void I2C_T_Command_Mode_receiveData(const uint8_t *tx_data, uint8_t tx_len,uint8_t id );
void I2C_A_Command_Mode_receiveData(const uint8_t *tx_data, uint8_t tx_len,uint8_t id );
void I2C_Command_Mode_receiveData(const uint8_t *tx_data, uint8_t tx_len,uint8_t id );
void I2C_Command_Mode_Send(uint8_t tx_len, uint8_t id);
void I2C_Diagnostic(uint8_t id);
void disable(void);
void i2c_enter_nomal_mode(void);
void i2c_read_ram_out0(void);
void i2c_read_ram_out1(void);
void i2c_read_all_ram(void);
void i2c_read_all_nvm(void);
void i2c_write_all_nvm(void);
void i2c_nvm_data(void);

1096
multical.COMPUTER1.mtud

File diff suppressed because one or more lines are too long

1174
multical.guseo.mtud

File diff suppressed because one or more lines are too long

2385
multical.mtpj

File diff suppressed because it is too large

188
multical.rcpe

@ -24,24 +24,38 @@
<Path>r_cg_cgc.h</Path>
<Path>r_cg_serial.h</Path>
<Path>r_cg_wdt.h</Path>
<Path>r_cg_adc.c</Path>
<Path>r_cg_adc_user.c</Path>
<Path>r_cg_adc.h</Path>
<Path>r_cg_port.c</Path>
<Path>r_cg_port_user.c</Path>
<Path>r_cg_port.h</Path>
</Category>
<Category Name="drivers">
<Path>..\IDH1.1\common.h</Path>
<Category Name="OWI">
<Path>..\IDH1.1\owi.c</Path>
<Path>..\IDH1.1\owi.h</Path>
<Path>owi.c</Path>
<Path>owi.h</Path>
</Category>
<Category Name="I2C">
<Path>..\IDH1.1\i2c.h</Path>
<Path>..\IDH1.1\i2c.c</Path>
<Path>i2c.c</Path>
<Path>i2c.h</Path>
</Category>
<Category Name="UART">
<Path>..\IDH1.1\uart.h</Path>
<Path>..\IDH1.1\uart.c</Path>
<Path>uart.c</Path>
<Path>uart.h</Path>
</Category>
<Category Name="Delay">
<Path>..\IDH1.1\delay.c</Path>
<Path>..\IDH1.1\delay.h</Path>
<Category Name="DELAY">
<Path>delay.c</Path>
<Path>delay.h</Path>
</Category>
<Category Name="anaout">
<Path>anaout.h</Path>
<Path>anaout.c</Path>
</Category>
<Path>common.h</Path>
<Category Name="dipSwitch">
<Path>dipSwitch.c</Path>
<Path>dipSwitch.h</Path>
</Category>
</Category>
</Files>
@ -66,12 +80,19 @@
<Path>DefaultBuild\r_cg_serial_user.obj</Path>
<Path>DefaultBuild\r_cg_wdt.obj</Path>
<Path>DefaultBuild\r_cg_wdt_user.obj</Path>
<Path>DefaultBuild\r_cg_adc.obj</Path>
<Path>DefaultBuild\r_cg_adc_user.obj</Path>
<Path>DefaultBuild\r_cg_port.obj</Path>
<Path>DefaultBuild\r_cg_port_user.obj</Path>
<Path>DefaultBuild\anaout.obj</Path>
<Path>DefaultBuild\owi.obj</Path>
<Path>DefaultBuild\i2c.obj</Path>
<Path>DefaultBuild\uart.obj</Path>
<Path>DefaultBuild\delay.obj</Path>
<Path>DefaultBuild\dipSwitch.obj</Path>
</LinkOrder>
<CommonOptions>
<IncludePathForC>..\..\Documents\카카오톡 받은 파일\IDH1.1\IDH1.1</IncludePathForC>
<IncludePathForC>..\IDH1.1</IncludePathForC>
<IncludePathForC>.</IncludePathForC>
</CommonOptions>
@ -84,6 +105,7 @@
<Option>-dev=%MicomToolPath%\Device\RL78\Devicefile\DR5F10PPJ.DVF</Option>
<Option>-g</Option>
<Option>-g_line</Option>
<Option>-I "..\..\Documents\카카오톡 받은 파일\IDH1.1\IDH1.1"</Option>
<Option>-I ..\IDH1.1</Option>
<Option>-I .</Option>
<Option>-c</Option>
@ -290,7 +312,7 @@
&lt;PORT Forcible="" /&gt;
&lt;/Effect&gt;
&lt;/IIC11&gt;
&lt;IICA0 Name="IICA0" Text="false" Comment="unused" Trigger="IICA0"&gt;
&lt;IICA0 Name="IICA0" Text="true" Comment="unused" Trigger="IICA0"&gt;
&lt;Effect&gt;
&lt;PORT Forcible="" /&gt;
&lt;/Effect&gt;
@ -366,7 +388,7 @@
&lt;/RTC1HZ&gt;
&lt;RXD0 Name="RXD0" Text="enable" /&gt;
&lt;ProjectName Name="PrjName" Text="multical" /&gt;
&lt;ProjectPath Name="PrjPath" Text="C:\Users\temp\Desktop\Amosense_Firmware" /&gt;
&lt;ProjectPath Name="PrjPath" Text="C:\Users\COMPUTER1\OneDrive\문서\카카오톡 받은 파일\Amosense_Firmware\Amosense_Firmware" /&gt;
&lt;ProjectKind Name="PrjKind" Text="Project78K0R" /&gt;
&lt;DeviceName Name="DeviceName" Fixed="" Text="RL78F14" /&gt;
&lt;MCUName Name="MCUName" Text="RL78F14_100pin" /&gt;
@ -411,6 +433,17 @@
&lt;/Effect&gt;
&lt;/TRDCLKUSE1&gt;
&lt;fMP Name="fMP" Value="64" /&gt;
&lt;ADPCForPort0 Name="ADPCForPort0" Value="255" /&gt;
&lt;ADPCForPort1 Name="ADPCForPort1" Value="255" /&gt;
&lt;ADPCForPort4 Name="ADPCForPort4" Value="255" /&gt;
&lt;ADPCForPort5 Name="ADPCForPort5" Value="255" /&gt;
&lt;ADPCForPort6 Name="ADPCForPort6" Value="255" /&gt;
&lt;ADPCForPort7 Name="ADPCForPort7" Value="255" /&gt;
&lt;ADPCForPort10 Name="ADPCForPort10" Value="255" /&gt;
&lt;ADPCForPort12 Name="ADPCForPort12" Value="255" /&gt;
&lt;ADPCForPort13 Name="ADPCForPort13" Value="255" /&gt;
&lt;ADPCForPort14 Name="ADPCForPort14" Value="255" /&gt;
&lt;ADPCForPort15 Name="ADPCForPort15" Value="255" /&gt;
&lt;GroupName Name="GroupName" Text="groupe" /&gt;
&lt;CodePath Name="CodePath" Text=".\" /&gt;
&lt;ReportType Name="ReportType" Text="Html" /&gt;
@ -430,17 +463,6 @@
&lt;HasHotRam Name="HasHotRam" Text="" /&gt;
&lt;PrjVersion Name="PrjVersion" Text="1.2.0.1" /&gt;
&lt;ProductVersion Name="ProductVersion" Text="4.08.06.01" /&gt;
&lt;ADPCForPort0 Name="ADPCForPort0" Value="255" /&gt;
&lt;ADPCForPort1 Name="ADPCForPort1" Value="255" /&gt;
&lt;ADPCForPort4 Name="ADPCForPort4" Value="255" /&gt;
&lt;ADPCForPort5 Name="ADPCForPort5" Value="255" /&gt;
&lt;ADPCForPort6 Name="ADPCForPort6" Value="255" /&gt;
&lt;ADPCForPort7 Name="ADPCForPort7" Value="255" /&gt;
&lt;ADPCForPort10 Name="ADPCForPort10" Value="255" /&gt;
&lt;ADPCForPort12 Name="ADPCForPort12" Value="255" /&gt;
&lt;ADPCForPort13 Name="ADPCForPort13" Value="255" /&gt;
&lt;ADPCForPort14 Name="ADPCForPort14" Value="255" /&gt;
&lt;ADPCForPort15 Name="ADPCForPort15" Value="255" /&gt;
&lt;LinkFileName Name="LinkFileName" Text="" /&gt;
&lt;/VAR&gt;
&lt;DIR&gt;
@ -502,8 +524,8 @@
&lt;Port6 Chip="RL78F14_80pin,RL78F14_100pin" Pullup="true"&gt;
&lt;P60 Name="P60/_SCK00/SCL00" PITHL="true" Nch="true" AltFunc="" Point="I/O" /&gt;
&lt;P61 Name="P61/SI00/SDA00/RXD0" PITHL="true" Nch="true" AltFunc="" Point="I/O" /&gt;
&lt;P62 Name="P62/SO00/TXD0/SCLA0" TTL="true" PITHL="true" Nch="true" AltFunc="" Point="I/O" /&gt;
&lt;P63 Name="P63/_SSI00/SDAA0" TTL="true" PITHL="true" Nch="true" AltFunc="" Point="I/O" /&gt;
&lt;P62 Name="P62/SO00/TXD0/SCLA0" TTL="true" PITHL="true" Nch="true" AltFunc="SCLA0" Point="I/O" /&gt;
&lt;P63 Name="P63/_SSI00/SDAA0" TTL="true" PITHL="true" Nch="true" AltFunc="SDAA0" Point="I/O" /&gt;
&lt;P64 Name="P64/TI14/TO14/SNZOUT3" AltFunc="" Point="I/O" /&gt;
&lt;P65 Name="P65/TI16/TO16/SNZOUT2" AltFunc="" Point="I/O" /&gt;
&lt;P66 Name="P66/TI00/TO00" AltFunc="" Point="I/O" /&gt;
@ -560,7 +582,7 @@
&lt;P127 Name="P127/TI03/TO03" Pullup="true" AltFunc="" Point="I/O" /&gt;
&lt;/Port12&gt;
&lt;Port13 Chip="RL78F14_48pin,RL78F14_64pin,RL78F14_80pin,RL78F14_100pin"&gt;
&lt;P130 Name="P130/RESOUT" AltFunc="" Point="O" /&gt;
&lt;P130 Name="P130/RESOUT" AltFunc="P130" Point="O" /&gt;
&lt;P137 Name="P137/INTP0" AltFunc="" Point="I" /&gt;
&lt;/Port13&gt;
&lt;Port14 Chip="RL78F14_48pin,RL78F14_64pin,RL78F14_80pin,RL78F14_100pin" Pullup="true"&gt;
@ -920,7 +942,7 @@
&lt;INTIIC11 InUse="0" ISR="r_iic11_interrupt" /&gt;
&lt;/SAU1&gt;
&lt;IICA0&gt;
&lt;INTIICA0 InUse="0" ISR="r_iica0_interrupt" /&gt;
&lt;INTIICA0 InUse="1" ISR="r_iica0_interrupt" /&gt;
&lt;/IICA0&gt;
&lt;/Serial&gt;
&lt;ADC&gt;
@ -1083,15 +1105,15 @@
&lt;r_cg_pfdl.h UserName="r_cg_pfdl.h" LibName="_pfdl.h" InUse="0" /&gt;
&lt;/CGC&gt;
&lt;PORT&gt;
&lt;r_cg_port.c UserName="r_cg_port.c" LibName=".c" InUse="0"&gt;
&lt;r_cg_port.c UserName="r_cg_port.c" LibName=".c" InUse="1"&gt;
&lt;Type R_PORT_Create="void R_PORT_Create(void)" /&gt;
&lt;R_PORT_Create UserName="R_PORT_Create" LibName="R_PORT_Create" Init="1" InitMode="" InUse="0" /&gt;
&lt;R_PORT_Create UserName="R_PORT_Create" LibName="R_PORT_Create" Init="1" InitMode="" InUse="1" /&gt;
&lt;/r_cg_port.c&gt;
&lt;r_cg_port_user.c UserName="r_cg_port_user.c" LibName="_user.c" InUse="0"&gt;
&lt;r_cg_port_user.c UserName="r_cg_port_user.c" LibName="_user.c" InUse="1"&gt;
&lt;Type R_PORT_Create_UserInit="void R_PORT_Create_UserInit(void)" /&gt;
&lt;R_PORT_Create_UserInit UserName="R_PORT_Create_UserInit" LibName="R_PORT_Create_UserInit" InUse="0" /&gt;
&lt;/r_cg_port_user.c&gt;
&lt;r_cg_port.h UserName="r_cg_port.h" LibName=".h" InUse="0" /&gt;
&lt;r_cg_port.h UserName="r_cg_port.h" LibName=".h" InUse="1" /&gt;
&lt;/PORT&gt;
&lt;INTC&gt;
&lt;r_cg_intc.c UserName="r_cg_intc.c" LibName=".c" InUse=""&gt;
@ -1279,16 +1301,16 @@
&lt;/IIC11&gt;
&lt;/SAU1&gt;
&lt;IICA0 Chip="RL78F14_32pin,RL78F14_48pin,RL78F14_64pin,RL78F14_80pin,RL78F14_100pin" InUse=""&gt;
&lt;R_IICA0_Create UserName="R_IICA0_Create" LibName="R_IICAn_Create" InUse="" Init="1" InitMode="" /&gt;
&lt;R_IICA0_Master_Send UserName="R_IICA0_Master_Send" LibName="R_IICAn_Master_Send" InUse="" /&gt;
&lt;R_IICA0_Master_Receive UserName="R_IICA0_Master_Receive" LibName="R_IICAn_Master_Receive" InUse="" /&gt;
&lt;R_IICA0_Slave_Send UserName="R_IICA0_Slave_Send" LibName="R_IICAn_Slave_Send" InUse="" /&gt;
&lt;R_IICA0_Slave_Receive UserName="R_IICA0_Slave_Receive" LibName="R_IICAn_Slave_Receive" InUse="" /&gt;
&lt;R_IICA0_Stop UserName="R_IICA0_Stop" LibName="R_IICAn_Stop" InUse="" /&gt;
&lt;R_IICA0_StopCondition UserName="R_IICA0_StopCondition" LibName="R_IICAn_StopCondition" InUse="" /&gt;
&lt;R_IICA0_Set_SnoozeOn UserName="R_IICA0_Set_SnoozeOn" LibName="R_IICAn_Set_SnoozeOn" InUse="" /&gt;
&lt;R_IICA0_Set_SnoozeOff UserName="R_IICA0_Set_SnoozeOff" LibName="R_IICAn_Set_SnoozeOff" InUse="" /&gt;
&lt;R_IICA0_Set_PowerOff UserName="R_IICA0_Set_PowerOff" LibName="R_IICAn_Set_PowerOff" InUse="" /&gt;
&lt;R_IICA0_Create UserName="R_IICA0_Create" LibName="R_IICAn_Create" InUse="1" Init="1" InitMode="" /&gt;
&lt;R_IICA0_Master_Send UserName="R_IICA0_Master_Send" LibName="R_IICAn_Master_Send" InUse="1" /&gt;
&lt;R_IICA0_Master_Receive UserName="R_IICA0_Master_Receive" LibName="R_IICAn_Master_Receive" InUse="1" /&gt;
&lt;R_IICA0_Slave_Send UserName="R_IICA0_Slave_Send" LibName="R_IICAn_Slave_Send" InUse="0" /&gt;
&lt;R_IICA0_Slave_Receive UserName="R_IICA0_Slave_Receive" LibName="R_IICAn_Slave_Receive" InUse="0" /&gt;
&lt;R_IICA0_Stop UserName="R_IICA0_Stop" LibName="R_IICAn_Stop" InUse="1" /&gt;
&lt;R_IICA0_StopCondition UserName="R_IICA0_StopCondition" LibName="R_IICAn_StopCondition" InUse="1" /&gt;
&lt;R_IICA0_Set_SnoozeOn UserName="R_IICA0_Set_SnoozeOn" LibName="R_IICAn_Set_SnoozeOn" InUse="0" /&gt;
&lt;R_IICA0_Set_SnoozeOff UserName="R_IICA0_Set_SnoozeOff" LibName="R_IICAn_Set_SnoozeOff" InUse="0" /&gt;
&lt;R_IICA0_Set_PowerOff UserName="R_IICA0_Set_PowerOff" LibName="R_IICAn_Set_PowerOff" InUse="0" /&gt;
&lt;/IICA0&gt;
&lt;/r_cg_serial.c&gt;
&lt;r_cg_serial_user.c UserName="r_cg_serial_user.c" LibName="_user.c" InUse="1"&gt;
@ -1364,15 +1386,15 @@
&lt;/IIC11&gt;
&lt;/SAU1&gt;
&lt;IICA0 Chip="RL78F14_32pin,RL78F14_48pin,RL78F14_64pin,RL78F14_80pin,RL78F14_100pin" InUse=""&gt;
&lt;R_IICA0_Create_UserInit UserName="R_IICA0_Create_UserInit" LibName="R_IICAn_Create_UserInit" InUse="" /&gt;
&lt;r_iica0_interrupt UserName="r_iica0_interrupt" INTHandle="" LibName="r_iican_interrupt" InUse="" /&gt;
&lt;r_iica0_callback_master_sendend UserName="r_iica0_callback_master_sendend" LibName="r_iican_callback_master_sendend" InUse="" /&gt;
&lt;r_iica0_callback_master_receiveend UserName="r_iica0_callback_master_receiveend" LibName="r_iican_callback_master_receiveend" InUse="" /&gt;
&lt;r_iica0_callback_slave_sendend UserName="r_iica0_callback_slave_sendend" LibName="r_iican_callback_slave_sendend" InUse="" /&gt;
&lt;r_iica0_callback_slave_receiveend UserName="r_iica0_callback_slave_receiveend" LibName="r_iican_callback_slave_receiveend" InUse="" /&gt;
&lt;r_iica0_callback_master_error UserName="r_iica0_callback_master_error" LibName="r_iican_callback_master_error" InUse="" /&gt;
&lt;r_iica0_callback_slave_error UserName="r_iica0_callback_slave_error" LibName="r_iican_callback_slave_error" InUse="" /&gt;
&lt;r_iica0_callback_getstopcondition UserName="r_iica0_callback_getstopcondition" LibName="r_iican_callback_getstopcondition" InUse="" /&gt;
&lt;R_IICA0_Create_UserInit UserName="R_IICA0_Create_UserInit" LibName="R_IICAn_Create_UserInit" InUse="0" /&gt;
&lt;r_iica0_interrupt UserName="r_iica0_interrupt" INTHandle="" LibName="r_iican_interrupt" InUse="1" /&gt;
&lt;r_iica0_callback_master_sendend UserName="r_iica0_callback_master_sendend" LibName="r_iican_callback_master_sendend" InUse="1" /&gt;
&lt;r_iica0_callback_master_receiveend UserName="r_iica0_callback_master_receiveend" LibName="r_iican_callback_master_receiveend" InUse="1" /&gt;
&lt;r_iica0_callback_slave_sendend UserName="r_iica0_callback_slave_sendend" LibName="r_iican_callback_slave_sendend" InUse="0" /&gt;
&lt;r_iica0_callback_slave_receiveend UserName="r_iica0_callback_slave_receiveend" LibName="r_iican_callback_slave_receiveend" InUse="0" /&gt;
&lt;r_iica0_callback_master_error UserName="r_iica0_callback_master_error" LibName="r_iican_callback_master_error" InUse="1" /&gt;
&lt;r_iica0_callback_slave_error UserName="r_iica0_callback_slave_error" LibName="r_iican_callback_slave_error" InUse="0" /&gt;
&lt;r_iica0_callback_getstopcondition UserName="r_iica0_callback_getstopcondition" LibName="r_iican_callback_getstopcondition" InUse="0" /&gt;
&lt;/IICA0&gt;
&lt;/r_cg_serial_user.c&gt;
&lt;r_cg_serial.h UserName="r_cg_serial.h" LibName=".h" InUse="1" /&gt;
@ -1886,8 +1908,8 @@
&lt;CGC Prepared="true" SetFlag="True" NeedRefresh="False"&gt;
&lt;CGC SetFlag="True" MacroName="cgc" /&gt;
&lt;/CGC&gt;
&lt;PORT HelpID="port" Prepared="true" SetFlag="False" NeedRefresh="False"&gt;
&lt;PORT SetFlag="False" MacroName="PORT" /&gt;
&lt;PORT HelpID="port" Prepared="true" SetFlag="True" NeedRefresh="False"&gt;
&lt;PORT SetFlag="True" MacroName="PORT" /&gt;
&lt;/PORT&gt;
&lt;INTC SetFlag="" HelpID="int" NeedRefresh="False"&gt;
&lt;INTP Accelerate="No" MacroName="INTP" /&gt;
@ -1902,7 +1924,7 @@
&lt;Channel0 Chip="RL78F14_100pin,RL78F14_80pin,RL78F14_64pin,RL78F14_48pin,RL78F14_32pin" UART="1" CSI="10" IIC="10" Channel="0" /&gt;
&lt;Channel1 Chip="RL78F14_100pin" PIOR43="0" UART="1" CSI="11" IIC="11" Channel="1" /&gt;
&lt;/SAU1&gt;
&lt;IICA0 Accelerate="No" Chip="RL78F14_32pin,RL78F14_48pin,RL78F14_64pin,RL78F14_80pin,RL78F14_100pin" MacroName="IICA" Channel="0" TabEnable="True" /&gt;
&lt;IICA0 Accelerate="No" Chip="RL78F14_32pin,RL78F14_48pin,RL78F14_64pin,RL78F14_80pin,RL78F14_100pin" MacroName="IICA" Channel="0" SetFlag="True" TabEnable="True" /&gt;
&lt;/Serial&gt;
&lt;ADC SetFlag="True" HelpID="adc" NeedRefresh="False"&gt;
&lt;ADC SetFlag="True" MacroName="ADC" /&gt;
@ -2030,7 +2052,7 @@
&lt;setting name="RECEIVE_PARITY_ODD" value="false" /&gt;
&lt;setting name="RECEIVE_PARITY_ZERO" value="false" /&gt;
&lt;setting name="RECEIVE_PARITY_NONE" value="true" /&gt;
&lt;setting name="RECEIVE_TRANSFER_BAUDRATE_VALUE" value="921600" /&gt;
&lt;setting name="RECEIVE_TRANSFER_BAUDRATE_VALUE" value="460800" /&gt;
&lt;setting name="CALLBACK_RECEIVE_END_USE" value="true" /&gt;
&lt;setting name="Receive_error_callback_function" value="generated" /&gt;
&lt;setting name="TRANSFER_MODE_CONTINUOUS" value="false" /&gt;
@ -2049,7 +2071,7 @@
&lt;setting name="TRANSMIT_PARITY_NONE" value="true" /&gt;
&lt;setting name="TRANSMIT_STOP_LENGTH_2_BITS" value="false" /&gt;
&lt;setting name="TRANSMIT_STOP_LENGTH_1_BIT" value="true" /&gt;
&lt;setting name="TRANSMIT_TRANSFER_BAUDRATE_VALUE" value="9600" /&gt;
&lt;setting name="TRANSMIT_TRANSFER_BAUDRATE_VALUE" value="460800" /&gt;
&lt;setting name="CALLBACK_TRANSMIT_END_USE" value="true" /&gt;
&lt;setting name="INT_PRIORITY_TRANSMIT_END" value="3" /&gt;
&lt;setting name="INT_PRIORITY_RECEPTION_END" value="3" /&gt;
@ -2116,7 +2138,7 @@
&lt;setting name="RECEIVE_PARITY_ODD" value="false" /&gt;
&lt;setting name="RECEIVE_PARITY_ZERO" value="false" /&gt;
&lt;setting name="RECEIVE_PARITY_NONE" value="true" /&gt;
&lt;setting name="RECEIVE_TRANSFER_BAUDRATE_VALUE" value="9600" /&gt;
&lt;setting name="RECEIVE_TRANSFER_BAUDRATE_VALUE" value="460800" /&gt;
&lt;setting name="CALLBACK_RECEIVE_END_USE" value="true" /&gt;
&lt;setting name="Receive_error_callback_function" value="generated" /&gt;
&lt;setting name="TRANSFER_MODE_CONTINUOUS" value="false" /&gt;
@ -2135,7 +2157,7 @@
&lt;setting name="TRANSMIT_PARITY_NONE" value="true" /&gt;
&lt;setting name="TRANSMIT_STOP_LENGTH_2_BITS" value="false" /&gt;
&lt;setting name="TRANSMIT_STOP_LENGTH_1_BIT" value="true" /&gt;
&lt;setting name="TRANSMIT_TRANSFER_BAUDRATE_VALUE" value="9600" /&gt;
&lt;setting name="TRANSMIT_TRANSFER_BAUDRATE_VALUE" value="460800" /&gt;
&lt;setting name="CALLBACK_TRANSMIT_END_USE" value="true" /&gt;
&lt;setting name="INT_PRIORITY_TRANSMIT_END" value="3" /&gt;
&lt;setting name="INT_PRIORITY_RECEPTION_END" value="3" /&gt;
@ -2190,8 +2212,46 @@
&lt;/SAU1&gt;
&lt;IICA0&gt;
&lt;setting name="SLAVE_MODE_USED" value="false" /&gt;
&lt;setting name="MODULE_UNUSE" value="true" /&gt;
&lt;setting name="SINGLE_MASTER_USED" value="false" /&gt;
&lt;setting name="MODULE_UNUSE" value="false" /&gt;
&lt;setting name="SINGLE_MASTER_USED" value="true" /&gt;
&lt;Slave0&gt;
&lt;setting name="CPU_PERIPHERAL_CLOCK" value="false" /&gt;
&lt;setting name="CPU_PERIPHERAL_CLOCK_HALF" value="true" /&gt;
&lt;setting name="LOCAL_ADDRESS_VALUE" value="16" /&gt;
&lt;setting name="TRANSFER_SPEED_STANDARD" value="true" /&gt;
&lt;setting name="TRANSFER_SPEED_HIGH" value="false" /&gt;
&lt;setting name="TRANSFER_SPEED_VALUE" value="" /&gt;
&lt;setting name="DIGITAL_FILITER_USED" value="false" /&gt;
&lt;setting name="INTERRUPT_IICA_PRIORITY" value="3" /&gt;
&lt;setting name="MASTER_RECEPT_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="MASTER_TRANSFER_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="MASTER_ERROR_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="MASTER_STOP_CONDITION_CALLBACK_USED" value="true" /&gt;
&lt;setting name="SLAVE_RECEPT_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="SLAVE_TRANSFER_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="SLAVE_ERROR_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="SLAVE_WAKEUP_MODE_ON" value="false" /&gt;
&lt;setting name="SLAVE_WAKEUP_MODE_OFF" value="true" /&gt;
&lt;/Slave0&gt;
&lt;Master0&gt;
&lt;setting name="CPU_PERIPHERAL_CLOCK" value="false" /&gt;
&lt;setting name="CPU_PERIPHERAL_CLOCK_HALF" value="true" /&gt;
&lt;setting name="LOCAL_ADDRESS_VALUE" value="16" /&gt;
&lt;setting name="TRANSFER_SPEED_STANDARD" value="true" /&gt;
&lt;setting name="TRANSFER_SPEED_HIGH" value="false" /&gt;
&lt;setting name="TRANSFER_SPEED_VALUE" value="100000" /&gt;
&lt;setting name="DIGITAL_FILITER_USED" value="false" /&gt;
&lt;setting name="INTERRUPT_IICA_PRIORITY" value="3" /&gt;
&lt;setting name="MASTER_RECEPT_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="MASTER_TRANSFER_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="MASTER_ERROR_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="MASTER_STOP_CONDITION_CALLBACK_USED" value="true" /&gt;
&lt;setting name="SLAVE_RECEPT_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="SLAVE_TRANSFER_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="SLAVE_ERROR_END_CALLBACK_USED" value="true" /&gt;
&lt;setting name="SLAVE_WAKEUP_MODE_ON" value="false" /&gt;
&lt;setting name="SLAVE_WAKEUP_MODE_OFF" value="true" /&gt;
&lt;/Master0&gt;
&lt;/IICA0&gt;
&lt;PORT&gt;
&lt;PortP0&gt;
@ -2556,21 +2616,23 @@
&lt;setting name="PSRSEL" value="false" /&gt;
&lt;/P61&gt;
&lt;P62&gt;
&lt;setting name="IIC_STATUS" value="used" /&gt;
&lt;setting name="MODULE_UNUSED" value="true" /&gt;
&lt;setting name="INPUT_MODE" value="false" /&gt;
&lt;setting name="OUTPUT_MODE" value="false" /&gt;
&lt;setting name="PULLUP_ON" value="false" /&gt;
&lt;setting name="NCH_ON" value="false" /&gt;
&lt;setting name="NCH_ON" value="true" /&gt;
&lt;setting name="OUTPUT_1" value="false" /&gt;
&lt;setting name="INPUT_BUFFER" value="0" /&gt;
&lt;setting name="PSRSEL" value="false" /&gt;
&lt;/P62&gt;
&lt;P63&gt;
&lt;setting name="IIC_STATUS" value="used" /&gt;
&lt;setting name="MODULE_UNUSED" value="true" /&gt;
&lt;setting name="INPUT_MODE" value="false" /&gt;
&lt;setting name="OUTPUT_MODE" value="false" /&gt;
&lt;setting name="PULLUP_ON" value="false" /&gt;
&lt;setting name="NCH_ON" value="false" /&gt;
&lt;setting name="NCH_ON" value="true" /&gt;
&lt;setting name="OUTPUT_1" value="false" /&gt;
&lt;setting name="INPUT_BUFFER" value="0" /&gt;
&lt;setting name="PSRSEL" value="false" /&gt;
@ -3028,9 +3090,9 @@
&lt;/PortP12&gt;
&lt;PortP13&gt;
&lt;P130&gt;
&lt;setting name="MODULE_UNUSED" value="true" /&gt;
&lt;setting name="MODULE_UNUSED" value="false" /&gt;
&lt;setting name="INPUT_MODE" value="false" /&gt;
&lt;setting name="OUTPUT_MODE" value="false" /&gt;
&lt;setting name="OUTPUT_MODE" value="true" /&gt;
&lt;setting name="PULLUP_ON" value="false" /&gt;
&lt;setting name="NCH_ON" value="false" /&gt;
&lt;setting name="OUTPUT_1" value="false" /&gt;

886
owi.c

@ -0,0 +1,886 @@
#include "owi.h"
#include "delay.h"
#include <string.h>
#include "uart.h"
/**
* : OWI_EnablePower
* : 1-Wire .
*
* :
*
* : (void)
*
* :
* - MCU P7의 1 (P7.1) HIGH(_02_Pn1_OUTPUT_1)
* 1-Wire .
*/
void OWI_EnablePower(void) {
P7 = _02_Pn1_OUTPUT_1;
}
/**
* : OWI_DisablePower
* : 1-Wire .
*
* :
*
* : (void)
*
* :
* - MCU P7의 1 (P7.1) LOW(_00_Pn1_OUTPUT_0)
* 1-Wire .
*/
void OWI_DisablePower(void) {
P7 = _00_Pn1_OUTPUT_0;
}
/**
* : GPIO_Clear
* : 1-Wire GPIO(P70) Low .
*
* :
*
* : (void)
*
* :
* - OWI_PORT_P (OWI_PIN_MASK) 0 P70을 Low로 .
* - OWI_PORT_PM 0 P70을 .
* - P70 Low .
*/
void GPIO_Clear(void) {
OWI_PORT_P &= ~OWI_PIN_MASK; // P70 = 0 (Low)
OWI_PORT_PM &= ~OWI_PIN_MASK; // P70 출력 모드
}
/**
* : GPIO_Input
* : 1-Wire GPIO(P70) .
*
* :
*
* : (void)
*
* :
* - OWI_PORT_PM (OWI_PIN_MASK) 1 P70을 (High-Z) .
* - .
*/
void GPIO_Input(void) {
OWI_PORT_PM |= OWI_PIN_MASK; // P70 입력 모드 (High-Z)
}
/**
* : GPIO_Read
* : 1-Wire GPIO(P70) .
*
* :
*
* :
* - 1 : P70 High
* - 0 : P70 Low
*
* :
* - OWI_PORT_P (OWI_PIN_MASK) .
* - 1 High, 0 Low로 .
* - , GPIO .
*/
int GPIO_Read(void) {
return (OWI_PORT_P & OWI_PIN_MASK) ? 1 : 0;
}
/**
* : OWI_Init
* : 1-Wire GPIO .
*
* :
* - bit_time_us : 1 ( )
*
* : (void)
*
* :
* 1. bit_period_us .
* 2. OWI_PORT_POM (OWI_PIN_MASK) Open-drain(n-channel) .
* 3. OWI_PORT_PU .
* 4. GPIO를 .
*
*/
void OWI_Init(uint32_t bit_time_us) {
bit_period_us = bit_time_us;
OWI_PORT_POM |= OWI_PIN_MASK; // Open-drain (n-channel)
OWI_PORT_PU |= OWI_PIN_MASK; // 내부 풀업 활성화
GPIO_Input(); // 초기엔 입력으로 대기
}
// ----------------------------------------
// OWI Start/Stop/Secure
// ----------------------------------------
/**
* : OWI_Start
* : 1-Wire Start .
*
* :
*
* : (void)
*
* :
* 1. GPIO_Clear() : P70 Low Start .
* 2. delay_us(TSTART_HOLD): Start .
* 3. GPIO_Input() : (High-Z) .
* 4. delay_us(TBIT / 2): 1-Wire .
*
*/
void OWI_Start(void)
{
GPIO_Clear();
delay_us(TSTART_HOLD);
GPIO_Input();
delay_us(TBIT / 2);
}
/**
* : OWI_Stop
* : 1-Wire .
*
* :
*
* : (void)
*
* :
* 1. GPIO_Input() : (High-Z) .
* 2. delay_us(TSTOP_LOW): Stop .
* 3. delay_us(TIDLE): .
* 4. GPIO_Clear() : Low로 .
*
*/
void OWI_Stop(void)
{
GPIO_Input();
delay_us(TSTOP_LOW);
delay_us(TIDLE);
GPIO_Clear();
}
/**
* : OWI_SecureStop
* : 1-Wire .
*
* :
*
* : (void)
*
* :
* 1. GPIO_Clear() SECURE_HIGH : Low .
* 2. SECURE_TOGGLE_COUNT만큼 :
* - GPIO_Input() High-Z SECURE_TOGGLE_HIGH .
* - GPIO_Clear() Low SECURE_TOGGLE_LOW .
* - .
* 3. GPIO_Input() SECURE_HIGH GPIO_Clear() TSTART_HOLD GPIO_Input() :
* - .
*
*/
void OWI_SecureStop(void)
{
int i;
GPIO_Clear();
delay_us(SECURE_HIGH);
for (i = 0; i < SECURE_TOGGLE_COUNT; i++) {
GPIO_Input();
delay_us(SECURE_TOGGLE_HIGH);
GPIO_Clear();
delay_us(SECURE_TOGGLE_LOW);
}
GPIO_Input();
delay_us(SECURE_HIGH);
GPIO_Clear();
delay_us(TSTART_HOLD);
GPIO_Input();
}
// ----------------------------------------
// OWI Bit/Byte Write & Read
// ----------------------------------------
/**
* : OWI_WriteBit
* : 1-Wire (bit) .
*
* :
* - bit : (0 1)
*
* : (void)
*
* :
* 1. Low (t_low) :
* - bit가 1 TLOW_1, 0 TLOW_0
* 2. t_high = TBIT - t_low : High .
* 3. GPIO_Input() : (High-Z) .
* 4. delay_us(t_high): High .
* 5. GPIO_Clear() : Low .
* 6. delay_us(t_low): Low .
*
*/
void OWI_WriteBit(int bit)
{
uint32_t t_low = bit ? TLOW_1 : TLOW_0;
uint32_t t_high = TBIT - t_low;
GPIO_Input(); // 풀업 상태 유지
delay_us(t_high); // High 유지
GPIO_Clear(); // Low로 드라이브
delay_us(t_low); // Low 시간 유지
}
/**
* : OWI_WriteByte
* : 1-Wire 1 .
*
* :
* - data : 1 (uint8_t)
*
* : (void)
*
* :
* 1. (MSB) (LSB) :
* - OWI_WriteBit() .
* - (data >> i) & 0x01 i번째 .
* 2. 8 GPIO_Input() :
* - High-Z .
*
*/
void OWI_WriteByte(uint8_t data)
{
int i;
for (i = 7; i >= 0; i--) {
OWI_WriteBit((data >> i) & 0x01);
}
GPIO_Input();
}
/**
* : OWI_ReadBit
* : 1-Wire .
*
* :
*
* :
* - 0 1 :
* - 0xFF :
*
* :
* 1. GPIO_Read() High가 :
* - 500us까지 (timeout).
* - UART로 0xFF .
* 2. delay_us(50) .
* 3. GPIO_Read() .
* 4. delay_us(30) .
* 5. .
*
*/
uint8_t OWI_ReadBit(void)
{
uint8_t bit;
int timeout = 500;
while (!(GPIO_Read()) && timeout-- > 0) {
delay_us(1);
}
if (timeout <= 0) {
uart_send_string("OWI Timeout\r\n");
return 0xFF;
}
delay_us(50);
bit = GPIO_Read();
delay_us(30);
return bit;
}
/**
* : OWI_ReadByte
* : 1-Wire 1 .
*
* :
*
* :
* - 1 (uint8_t)
*
* :
* 1. (MSB) (LSB) :
* - OWI_ReadBit() 1 .
* - data .
* 2. 8 data .
*
*/
uint8_t OWI_ReadByte(void)
{
uint8_t data = 0;
int i;
for (i = 7; i >= 0; i--) {
data |= (OWI_ReadBit() << i);
}
return data;
}
/**
* : OWI_T_ReadBytesAndPrint
* : 1-Wire , UART로 .
*
* :
* - length :
*
* : (void)
*
* :
* 1. buf length만큼 OWI_ReadByte() 1 .
* 2. (buf[0]) 16 2 UART .
* 3. 16 4 UART :
* - delay(10000) .
* 4. UART sprintf strcpy uart_send_string .
*
* :
* - buf[0] , 2 .
* - delay를 UART .
* - 1-Wire .
*/
void OWI_T_ReadBytesAndPrint(int length)
{
uint8_t buf[129];
int i;
char uart_buf[8];
char tmp_buf[8];
uint8_t va0, va1;
for (i = 0; i < length; i++) {
buf[i] = OWI_ReadByte();
}
sprintf(uart_buf, "%02X ", buf[0]);
strcpy(tmp_buf, uart_buf);
uart_send_string(tmp_buf);
for (i = 1; i < length; i+=2) {
va0 = buf[i];
va1 = buf[i+1];
delay(10000);
sprintf(uart_buf, "%02X%02X ", va0, va1);
strcpy(tmp_buf, uart_buf);
uart_send_string(tmp_buf);
delay(10000);
}
}
/**
* : OWI_A_CommandMode
* : 1-Wire ADC (CMD) UART로 .
*
* :
* - tx_data : (3)
* - tx_len :
* - id : ID
*
* : (void)
*
* :
* 1) ADC
* - ADC_ReadAndSend_UART() ADC .
* - g_adc_bytes 2 line .
* - ADC "Err:adc_count" .
*
* 2) 1-Wire
* - OWI_EnablePower() .
* - 7ms .
*
* 3) (CMD)
* - CMD_LIST에 6 4 .
* - / OWI_SecureStop() .
* - read_address(0x51) .
* - 0xFF OWI_MAX_RETRY만큼 .
* - Rx 2, 3 line 16 .
*
* 4) CMD (tx_data )
* - tx_len가 3 ID를 write read .
* - Rx 0xFF OWI_MAX_RETRY .
* - line 2, 3 .
* - tx_data가 "0000" line .
*
* 5) UART
* - line CRLF uart_send_string() .
*
* 6)
* - delay(10000) OWI_DisablePower() .
*
* :
* - OWI_SecureStop() delay_us() 1-Wire .
* - g_adc_bytes, RAM_BYTES, OWI_MAX_RETRY .
* - UART로 ADC값, CMD , CMD .
*/
#define OWI_MAX_RETRY 2 // 재시도 2회
#define OWI_RECOVERY_MIN_US 500 // datasheet 기준 최소 recovery 시간
void OWI_A_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id)
{
uint8_t CMD_LIST[6][4] = {
{0x50,0x2E,0x00,0x00}, // BR
{0x50,0x2E,0x01,0x00}, // BR_AZ
{0x50,0x2E,0x02,0x00}, // T_RAW
{0x50,0x2E,0x16,0x00}, // Y_data
{0x50,0x2E,0x41,0x00}, // BR_AOUT
{0x50,0x2E,0x00,0x00} // BR_AOUT duplicate
};
char line[128];
size_t n = 0;
uint8_t rx[RAM_BYTES];
int i, j, retry, all_ff;
float v;
uint8_t read_address = 0x51;
// ===== 1) ADC 읽기 =====
ADC_ReadAndSend_UART();
if (g_adc_len != ADC_NUM_CH) {
uart_send_string("Err:adc_count\r\n");
return;
}
for (j = 0; j < g_adc_len; j++) {
v = g_adc_bytes[j];
n += sprintf(&line[n], "%.2f", v);
if (j + 1 < g_adc_len) line[n++] = ',';
}
line[n++] = ',';
// ===== 2) OWI Power On =====
OWI_EnablePower();
delay_us(7000); // Power-on delay
// ===== 3) CMD 전송 및 안전한 읽기 =====
for (j = 0; j < 6; j++) {
OWI_SecureStop();
for (i = 0; i < 4; i++) OWI_WriteByte(CMD_LIST[j][i]);
OWI_Stop();
// CMD → read 회복 시간
delay_us(OWI_RECOVERY_MIN_US);
// Rx 초기화
for (i = 0; i < RAM_BYTES; i++) rx[i] = 0xFF;
for (retry = 0; retry <= OWI_MAX_RETRY; retry++) {
// read 전 충분한 recovery 확보
delay_us(OWI_RECOVERY_MIN_US);
OWI_SecureStop();
OWI_WriteByte(read_address);
for (i = 0; i < RAM_BYTES; i++) rx[i] = OWI_ReadByte();
OWI_Stop();
all_ff = 1;
for (i = 0; i < RAM_BYTES; i++) {
if (rx[i] != 0xFF) { all_ff = 0; break; }
}
if (!all_ff) break; // 정상 데이터 수신
if (retry == OWI_MAX_RETRY) { // 모든 재시도 실패
OWI_DisablePower();
return;
}
}
n += sprintf(&line[n], "%02X%02X", rx[1], rx[2]);
line[n++] = ',';
}
// ===== 4) 사용자 CMD 처리 =====
if (tx_data != NULL && tx_len == 3) {
for (retry = 0; retry <= OWI_MAX_RETRY; retry++) {
// write CMD
OWI_SecureStop();
OWI_WriteByte(id << 1);
for (i = 0; i < 3; i++) OWI_WriteByte(tx_data[i]);
OWI_Stop();
// read 준비
delay_us(OWI_RECOVERY_MIN_US);
// read
for (i = 0; i < RAM_BYTES; i++) rx[i] = 0xFF;
OWI_SecureStop();
OWI_WriteByte((id << 1) | 1);
for (i = 0; i < RAM_BYTES; i++) rx[i] = OWI_ReadByte();
OWI_Stop();
all_ff = 1;
for (i = 0; i < RAM_BYTES; i++) {
if (rx[i] != 0xFF) { all_ff = 0; break; }
}
if (!all_ff) break;
if (retry == OWI_MAX_RETRY) {
OWI_DisablePower();
return;
}
}
n += sprintf(&line[n], "%02X%02X", rx[1], rx[2]);
} else {
n += sprintf(&line[n], "0000");
}
// ===== 5) UART 출력 =====
line[n++] = '\r';
line[n++] = '\n';
line[n] = '\0';
uart_send_string(line);
delay(10000);
OWI_DisablePower();
}
/**
* : OWI_Diagnostic
* : 1-Wire UART로 .
*
* :
* - id : ID ( )
*
* : (void)
*
* :
* 1) CMD_LIST에 10 4 .
* - OWI_SecureStop() .
* - OWI_Stop() .
* - OWI_RECOVERY_MIN_US .
*
* 2) read_address(0x51) .
* - Rx (0xFF) OWI_ReadByte() .
* - 0xFF OWI_MAX_RETRY만큼 .
*
* 3) rx[1], rx[2] 16 line .
* - (,) .
*
* 4) UART
* - line CRLF uart_send_string() .
*
* :
* - OWI_SecureStop() delay_us() 1-Wire .
* - .
*/
void OWI_Diagnostic(uint8_t id)
{
uint8_t CMD_LIST[10][4] = {
{0x50,0x2E,0x01,0x00}, // BR
{0x50,0x2E,0x00,0x00}, // BR_AZ
{0x50,0x2E,0x02,0x00}, // T_RAW
{0x50,0x2E,0x03,0x00}, // Y_data
{0x50,0x2E,0x21,0x00}, // BR_AOUT
{0x50,0x2E,0x04,0x00},
{0x50,0x2E,0x05,0x00},
{0x50,0x2E,0x07,0x00},
{0x50,0x2E,0x19,0x00},
{0x50,0x2E,0x0B,0x00}
};
char line[128];
size_t n = 0;
uint8_t rx[RAM_BYTES];
int i, j, retry, all_ff;
float v;
uint8_t read_address = 0x51;
// ===== 3) CMD 전송 및 안전한 읽기 =====
for (j = 0; j < 10; j++) {
OWI_SecureStop();
for (i = 0; i < 4; i++) OWI_WriteByte(CMD_LIST[j][i]);
OWI_Stop();
// CMD → read 회복 시간
delay_us(OWI_RECOVERY_MIN_US);
// Rx 초기화
for (i = 0; i < RAM_BYTES; i++) rx[i] = 0xFF;
for (retry = 0; retry <= OWI_MAX_RETRY; retry++) {
// read 전 충분한 recovery 확보
delay_us(OWI_RECOVERY_MIN_US);
OWI_SecureStop();
OWI_WriteByte(read_address);
for (i = 0; i < RAM_BYTES; i++) rx[i] = OWI_ReadByte();
OWI_Stop();
all_ff = 1;
for (i = 0; i < RAM_BYTES; i++) {
if (rx[i] != 0xFF) { all_ff = 0; break; }
}
if (!all_ff) break; // 정상 데이터 수신
if (retry == OWI_MAX_RETRY) { // 모든 재시도 실패
OWI_DisablePower();
return;
}
}
// 데이터 추가
n += sprintf(&line[n], "%02X%02X", rx[1], rx[2]);
// 마지막이 아닐 때만 콤마 추가
if (j < 9) {
line[n++] = ',';
}
}
// ===== 5) UART 출력 =====
line[n++] = '\r';
line[n++] = '\n';
line[n] = '\0';
uart_send_string(line);
delay(10000);
}
/**
* : OWI_disable
* : 1-Wire , UART로 .
*
* :
*
* : (void)
*
* :
* 1) OWI_DisablePower() 1-Wire .
* 2) UART로 "51" CRLF .
*
* :
* - UART .
*/
void OWI_disable()
{
OWI_DisablePower();
uart_send_string("51\r\n");
}
/**
* : OWI_T_CommandMode
* : 1-Wire , UART로 .
*
* :
* - tx_data :
* - tx_len :
* - id : 1-Wire ID ( )
*
* : (void)
*
* :
* 1) 1-Wire
* - OWI_EnablePower()
* - 7ms
*
* 2) 1-Wire
* - OWI_Init()
*
* 3) (Write sequence)
* - OWI_SecureStop()
* - (id << 1) ( )
* - tx_data
* - OWI_Stop()
*
* 4) UART
* - "51"
*
* :
* - , .
* - OWI_SecureStop() OWI_Stop() 1-Wire .
*/
void OWI_T_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id)
{
uint8_t rx[3] = {0};
char uart_buf[16];
int i;
OWI_EnablePower();
delay_us(7000); // Power-on delay
OWI_Init(OWI_BIT_PERIOD_US);
// Write sequence (슬레이브 주소와 명령 전송)
OWI_SecureStop(); // 통신 준비
OWI_WriteByte(id << 1); // 슬레이브 write 주소
for (i = 0; i < tx_len; i++) {
OWI_WriteByte(tx_data[i]); // 명령 전송
}
OWI_Stop(); // 쓰기 종료
uart_send_string("51\r\n");
}
/**
* : OWI_CommandMode
* : 1-Wire , UART로 .
*
* :
* - tx_data :
* - tx_len :
* - id : 1-Wire ID ( )
*
* : (void)
*
* :
* 1) (Write sequence)
* - OWI_SecureStop()
* - (id << 1) ( )
* - tx_data
* - OWI_Stop()
*
* 2) UART
* - "51"
*
* :
* - /
* - ,
* - OWI_SecureStop() OWI_Stop() 1-Wire
*/
void OWI_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id)
{
uint8_t rx[3] = {0};
char uart_buf[16];
int i;
// Write sequence (슬레이브 주소와 명령 전송)
OWI_SecureStop(); // 통신 준비
OWI_WriteByte(id << 1); // 슬레이브 write 주소
for (i = 0; i < tx_len; i++) {
OWI_WriteByte(tx_data[i]); // 명령 전송
}
OWI_Stop(); // 쓰기 종료
uart_send_string("51\r\n");
}
/**
* : OWI_ReadBytesAndPrint
* : 1-Wire , UART로 .
*
* :
* - length :
* - id : 1-Wire ID ( )
*
* : (void)
*
* :
* 1)
* - OWI_SecureStop()
* - (id << 1) | 1
*
* 2) length만큼 OWI_ReadByte()
* - buf
*
* 3) UART
* - buf[0]
* - 1
* -
* - delay(10000) (UART )
* - : 16
* - CRLF("\r\n")
*
* :
* - UART (uart_buf, tmp_buf)
* - delay를
*/
void OWI_ReadBytesAndPrint(int length, uint8_t id)
{
uint8_t buf[600];
int i;
char uart_buf[8];
char tmp_buf[8];
uint8_t va0, va1;
OWI_SecureStop();
OWI_WriteByte((id << 1) | 1);
for (i = 0; i < length; i++) {
buf[i] = OWI_ReadByte();
}
sprintf(uart_buf, "%02X ", buf[0]);
strcpy(tmp_buf, uart_buf);
uart_send_string(tmp_buf);
for (i = 1; i < length; i += 2) {
va0 = buf[i];
if (i + 1 < length) {
// 완전한 페어
va1 = buf[i + 1];
delay(10000);
sprintf(uart_buf, "%02X%02X ", va0, va1);
strcpy(tmp_buf, uart_buf);
uart_send_string(tmp_buf);
delay(10000);
} else {
// 마지막 1바이트가 남은 경우 단독 출력
delay(10000);
sprintf(uart_buf, "%02X", va0);
strcpy(tmp_buf, uart_buf);
uart_send_string(tmp_buf);
delay(10000);
}
}
uart_send_string("\r\n");
}

48
owi.h

@ -0,0 +1,48 @@
#include "r_cg_macrodriver.h"
#include "r_cg_serial.h"
#include "r_cg_port.h"
// OWI에 사용할 핀 정의 (P70)
#define OWI_PORT_P P7 // 포트 출력 레지스터
#define OWI_PORT_PM PM7 // 포트 방향 (1: 입력, 0: 출력)
#define OWI_PORT_PU PU7 // 내부 풀업
#define OWI_PORT_POM POM7 // Open-drain 설정
#define OWI_PIN_MASK (1 << 0) // P70 = bit 0
#define OWI_BIT_PERIOD_US 100
#define TBIT OWI_BIT_PERIOD_US
#define TLOW_0 (TBIT * 0.75) // 75us
#define TLOW_1 (TBIT * 0.25) // 225us
#define TSTOP_LOW (TBIT * 2) // 600us
#define TIDLE (TBIT * 3) // 900us
#define TSTART_HOLD 50 // ≥25us 기준으로 50us 확보
#define SECURE_HIGH 250
#define SECURE_TOGGLE_COUNT 3
#define SECURE_TOGGLE_LOW 40
#define SECURE_TOGGLE_HIGH 60
static uint32_t bit_period_us = 100; // 기본 OWI 비트 시간
void OWI_EnablePower(void);
void OWI_DisablePower(void);
void GPIO_Clear(void);
void GPIO_Input(void);
int GPIO_Read(void);
void OWI_Init(uint32_t bit_time_us);
void OWI_Start(void);
void OWI_Stop(void);
void OWI_SecureStop(void);
void OWI_WriteBit(int bit);
void OWI_WriteByte(uint8_t data);
uint8_t OWI_ReadBit(void);
uint8_t OWI_ReadByte(void);
void OWI_T_ReadBytesAndPrint(int length);
void OWI_ReadBytesAndPrint(int length, uint8_t id);
void OWI_T_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id);
void OWI_A_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id);
void owi_write_coefficients(void);
void OWI_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id);
void OWI_disable();
void OWI_Diagnostic(uint8_t id);

161
r_cg_adc.c

@ -0,0 +1,161 @@
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_cg_adc.c
* Version : CodeGenerator for RL78/F14 V2.03.07.02 [08 Nov 2021]
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for ADC module.
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_adc.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
* Function Name: R_ADC_Create
* Description : This function initializes the AD converter.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_ADC_Create(void)
{
ADCEN = 1U; /* supply AD clock */
ADM0 = _00_AD_ADM0_INITIALVALUE; /* disable AD conversion and clear ADM0 register */
ADMK = 1U; /* disable INTAD interrupt */
ADIF = 0U; /* clear INTAD interrupt flag */
/* Set INTAD low priority */
ADPR1 = 1U;
ADPR0 = 1U;
/* The reset status of ADPC is analog input, so it's unnecessary to set. */
/* Set ANI0 - ANI23 pin as analog input */
PM10 |= 0x3FU;
PM9 |= 0xFFU;
PM8 |= 0xFFU;
PM3 |= 0x18U;
/* Set ANI24 pin */
PMC12 |= 0x20U;
PM12 |= 0x20U;
/* Set ANI25 pin */
PMC12 |= 0x01U;
PM12 |= 0x01U;
/* Set ANI26 pin */
PMC7 |= 0x01U;
PM7 |= 0x01U;
/* Set ANI27 pin */
PMC7 |= 0x02U;
PM7 |= 0x02U;
/* Set ANI28 pin */
PMC7 |= 0x04U;
PM7 |= 0x04U;
/* Set ANI29 pin */
PMC7 |= 0x08U;
PM7 |= 0x08U;
/* Set ANI30 pin */
PMC7 |= 0x10U;
PM7 |= 0x10U;
ADM0 = _00_AD_CONVERSION_CLOCK_64 | _00_AD_TIME_MODE_NORMAL_1 | _00_AD_OPERMODE_SELECT;
ADM1 = _00_AD_TRIGGER_SOFTWARE | _00_AD_CONVMODE_CONSELECT;
ADM2 = _00_AD_POSITIVE_VDD | _00_AD_NEGATIVE_VSS | _00_AD_AREA_MODE_1 | _00_AD_RESOLUTION_10BIT;
ADUL = _FF_AD_ADUL_VALUE;
ADLL = _00_AD_ADLL_VALUE;
ADS = _00_AD_INPUT_CHANNEL_0;
}
/***********************************************************************************************************************
* Function Name: R_ADC_Start
* Description : This function starts the AD converter.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_ADC_Start(void)
{
ADIF = 0U; /* clear INTAD interrupt flag */
ADMK = 0U; /* enable INTAD interrupt */
ADCS = 1U; /* enable AD conversion */
}
/***********************************************************************************************************************
* Function Name: R_ADC_Stop
* Description : This function stops the AD converter.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_ADC_Stop(void)
{
ADCS = 0U; /* disable AD conversion */
ADMK = 1U; /* disable INTAD interrupt */
ADIF = 0U; /* clear INTAD interrupt flag */
}
/***********************************************************************************************************************
* Function Name: R_ADC_Set_OperationOn
* Description : This function enables comparator operation.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_ADC_Set_OperationOn(void)
{
ADCE = 1U; /* enable AD comparator */
}
/***********************************************************************************************************************
* Function Name: R_ADC_Set_OperationOff
* Description : This function stops comparator operation.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_ADC_Set_OperationOff(void)
{
ADCE = 0U; /* disable AD comparator */
}
/***********************************************************************************************************************
* Function Name: R_ADC_Get_Result
* Description : This function returns the conversion result in the buffer.
* Arguments : buffer -
* the address where to write the conversion result
* Return Value : None
***********************************************************************************************************************/
void R_ADC_Get_Result(uint16_t * const buffer)
{
*buffer = (uint16_t)(ADCR >> 6U);
}
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

223
r_cg_adc.h

@ -0,0 +1,223 @@
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_cg_adc.h
* Version : CodeGenerator for RL78/F14 V2.03.07.02 [08 Nov 2021]
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for ADC module.
* Creation Date: 2026-01-13
***********************************************************************************************************************/
#ifndef ADC_H
#define ADC_H
/***********************************************************************************************************************
Macro definitions (Register bit)
***********************************************************************************************************************/
/*
Peripheral enable register 0 (PER0)
*/
/* Control of AD converter input clock (ADCEN) */
#define _00_AD_CLOCK_STOP (0x00U) /* stop supply of input clock */
#define _20_AD_CLOCK_SUPPLY (0x20U) /* supply input clock */
/*
AD converter mode register 0 (ADM0)
*/
#define _00_AD_ADM0_INITIALVALUE (0x00U)
/* AD conversion operation control (ADCS) */
#define _80_AD_CONVERSION_ENABLE (0x80U) /* enable AD conversion operation control */
#define _00_AD_CONVERSION_DISABLE (0x00U) /* disable AD conversion operation control */
/* Specification of AD conversion operation mode (ADMD) */
#define _00_AD_OPERMODE_SELECT (0x00U) /* select operation mode */
#define _40_AD_OPERMODE_SCAN (0x40U) /* scan operation mode */
/* AD conversion clock selection (FR2 - FR0) */
#define _00_AD_CONVERSION_CLOCK_64 (0x00U) /* fCLK/64 */
#define _08_AD_CONVERSION_CLOCK_32 (0x08U) /* fCLK/32 */
#define _10_AD_CONVERSION_CLOCK_16 (0x10U) /* fCLK/16 */
#define _18_AD_CONVERSION_CLOCK_8 (0x18U) /* fCLK/8 */
#define _20_AD_CONVERSION_CLOCK_6 (0x20U) /* fCLK/6 */
#define _28_AD_CONVERSION_CLOCK_5 (0x28U) /* fCLK/5 */
#define _30_AD_CONVERSION_CLOCK_4 (0x30U) /* fCLK/4 */
#define _38_AD_CONVERSION_CLOCK_2 (0x38U) /* fCLK/2 */
/* Specification AD conversion time mode (LV1, LV0) */
#define _00_AD_TIME_MODE_NORMAL_1 (0x00U) /* normal 1 mode */
#define _02_AD_TIME_MODE_NORMAL_2 (0x02U) /* normal 2 mode */
/* AD comparator operation control (ADCE) */
#define _01_AD_COMPARATOR_ENABLE (0x01U) /* enable comparator operation control */
#define _00_AD_COMPARATOR_DISABLE (0x00U) /* disable comparator operation control */
/*
Analog input channel specification register (ADS)
*/
/* Specification of analog input channel (ADISS, ADS4 - ADS0) */
/* Select mode */
#define _00_AD_INPUT_CHANNEL_0 (0x00U) /* ANI0 */
#define _01_AD_INPUT_CHANNEL_1 (0x01U) /* ANI1 */
#define _02_AD_INPUT_CHANNEL_2 (0x02U) /* ANI2 */
#define _03_AD_INPUT_CHANNEL_3 (0x03U) /* ANI3 */
#define _04_AD_INPUT_CHANNEL_4 (0x04U) /* ANI4 */
#define _05_AD_INPUT_CHANNEL_5 (0x05U) /* ANI5 */
#define _06_AD_INPUT_CHANNEL_6 (0x06U) /* ANI6 */
#define _07_AD_INPUT_CHANNEL_7 (0x07U) /* ANI7 */
#define _08_AD_INPUT_CHANNEL_8 (0x08U) /* ANI8 */
#define _09_AD_INPUT_CHANNEL_9 (0x09U) /* ANI9 */
#define _0A_AD_INPUT_CHANNEL_10 (0x0AU) /* ANI10 */
#define _0B_AD_INPUT_CHANNEL_11 (0x0BU) /* ANI11 */
#define _0C_AD_INPUT_CHANNEL_12 (0x0CU) /* ANI12 */
#define _0D_AD_INPUT_CHANNEL_13 (0x0DU) /* ANI13 */
#define _0E_AD_INPUT_CHANNEL_14 (0x0EU) /* ANI14 */
#define _0F_AD_INPUT_CHANNEL_15 (0x0FU) /* ANI15 */
#define _10_AD_INPUT_CHANNEL_16 (0x10U) /* ANI16 */
#define _11_AD_INPUT_CHANNEL_17 (0x11U) /* ANI17 */
#define _12_AD_INPUT_CHANNEL_18 (0x12U) /* ANI18 */
#define _13_AD_INPUT_CHANNEL_19 (0x13U) /* ANI19 */
#define _14_AD_INPUT_CHANNEL_20 (0x14U) /* ANI20 */
#define _15_AD_INPUT_CHANNEL_21 (0x15U) /* ANI21 */
#define _16_AD_INPUT_CHANNEL_22 (0x16U) /* ANI22 */
#define _17_AD_INPUT_CHANNEL_23 (0x17U) /* ANI23 */
#define _18_AD_INPUT_CHANNEL_24 (0x18U) /* ANI24 */
#define _19_AD_INPUT_CHANNEL_25 (0x19U) /* ANI25 */
#define _1A_AD_INPUT_CHANNEL_26 (0x1AU) /* ANI26 */
#define _1B_AD_INPUT_CHANNEL_27 (0x1BU) /* ANI27 */
#define _1C_AD_INPUT_CHANNEL_28 (0x1CU) /* ANI28 */
#define _1D_AD_INPUT_CHANNEL_29 (0x1DU) /* ANI29 */
#define _1E_AD_INPUT_CHANNEL_30 (0x1EU) /* ANI30 */
#define _80_AD_INPUT_TEMPERSENSOR_0 (0x80U) /* temperature sensor 0 output is used to be the input channel */
#define _81_AD_INPUT_INTERREFVOLT (0x81U) /* internal reference voltage output is used to be the input channel */
/* Scan mode */
#define _00_AD_INPUT_CHANNEL_0_3 (0x00U) /* ANI0 - ANI3 */
#define _01_AD_INPUT_CHANNEL_1_4 (0x01U) /* ANI1 - ANI4 */
#define _02_AD_INPUT_CHANNEL_2_5 (0x02U) /* ANI2 - ANI5 */
#define _03_AD_INPUT_CHANNEL_3_6 (0x03U) /* ANI3 - ANI6 */
#define _04_AD_INPUT_CHANNEL_4_7 (0x04U) /* ANI4 - ANI7 */
#define _05_AD_INPUT_CHANNEL_5_8 (0x05U) /* ANI5 - ANI8 */
#define _06_AD_INPUT_CHANNEL_6_9 (0x06U) /* ANI6 - ANI9 */
#define _07_AD_INPUT_CHANNEL_7_10 (0x07U) /* ANI7 - ANI10 */
#define _08_AD_INPUT_CHANNEL_8_11 (0x08U) /* ANI8 - ANI11 */
#define _09_AD_INPUT_CHANNEL_9_12 (0x09U) /* ANI9 - ANI12 */
#define _0A_AD_INPUT_CHANNEL_10_13 (0x0AU) /* ANI10 - ANI13 */
#define _0B_AD_INPUT_CHANNEL_11_14 (0x0BU) /* ANI11 - ANI14 */
#define _0C_AD_INPUT_CHANNEL_12_15 (0x0CU) /* ANI12 - ANI15 */
#define _0D_AD_INPUT_CHANNEL_13_16 (0x0DU) /* ANI13 - ANI16 */
#define _0E_AD_INPUT_CHANNEL_14_17 (0x0EU) /* ANI14 - ANI17 */
#define _0F_AD_INPUT_CHANNEL_15_18 (0x0FU) /* ANI15 - ANI18 */
#define _10_AD_INPUT_CHANNEL_16_19 (0x10U) /* ANI16 - ANI19 */
#define _11_AD_INPUT_CHANNEL_17_20 (0x11U) /* ANI17 - ANI20 */
#define _12_AD_INPUT_CHANNEL_18_21 (0x12U) /* ANI18 - ANI21 */
#define _13_AD_INPUT_CHANNEL_19_22 (0x13U) /* ANI19 - ANI22 */
#define _14_AD_INPUT_CHANNEL_20_23 (0x14U) /* ANI20 - ANI23 */
/*
AD converter mode register 1 (ADM1)
*/
/* AD trigger mode selection (ADTMD1, ADTMD0) */
#define _00_AD_TRIGGER_SOFTWARE (0x00U) /* software trigger mode */
#define _80_AD_TRIGGER_HARDWARE_NOWAIT (0x80U) /* hardware trigger mode (no wait) */
#define _C0_AD_TRIGGER_HARDWARE_WAIT (0xC0U) /* hardware trigger mode (wait) */
/* AD convertion mode selection (ADSCM) */
#define _00_AD_CONVMODE_CONSELECT (0x00U) /* continuous convertion mode */
#define _20_AD_CONVMODE_ONESELECT (0x20U) /* oneshot convertion mode */
/* Trigger signal selection (ADTRS1, ADTRS0) */
#define _00_AD_TRIGGER_INTTM01 (0x00U) /* INTTM01 */
#define _01_AD_TRIGGER_ELC (0x01U) /* ELC */
#define _01_AD_TRIGGER_TIMER (0x01U) /* INTTRD0,INTTRJ0 */
#define _02_AD_TRIGGER_INTRTC (0x02U) /* INTRTC */
/*
AD converter mode register 2 (ADM2)
*/
/* AD VREF(+) selection (ADREFP1, ADREFP0) */
#define _00_AD_POSITIVE_VDD (0x00U) /* use VDD as VREF(+) */
#define _40_AD_POSITIVE_AVREFP (0x40U) /* use AVREFP as VREF(+) */
#define _80_AD_POSITIVE_INTERVOLT (0x80U) /* use internal voltage as VREF(+) */
/* AD VREF(-) selection (ADREFM) */
#define _00_AD_NEGATIVE_VSS (0x00U) /* use VSS as VREF(-) */
#define _20_AD_NEGATIVE_AVREFM (0x20U) /* use AVREFM as VREF(-) */
/* AD conversion result upper/lower bound value selection (ADRCK) */
#define _00_AD_AREA_MODE_1 (0x00U) /* generates INTAD when ADLL <= ADCRH <= ADUL */
#define _08_AD_AREA_MODE_2_3 (0x08U) /* generates INTAD when ADUL < ADCRH or ADLL > ADCRH */
/* AD wakeup function selection (AWC) */
#define _00_AD_WAKEUP_OFF (0x00U) /* stop wakeup function */
#define _04_AD_WAKEUP_ON (0x04U) /* use wakeup function */
/* AD resolution selection (ADTYP) */
#define _00_AD_RESOLUTION_10BIT (0x00U) /* 10 bits */
#define _01_AD_RESOLUTION_8BIT (0x01U) /* 8 bits */
/*
AD test function register (ADTES)
*/
/* AD test mode signal (ADTES2 - ADTES0) */
#define _00_AD_NORMAL_INPUT (0x00U) /* normal mode */
#define _02_AD_TEST_AVREFM (0x02U) /* use AVREFM as test signal */
#define _03_AD_TEST_AVREFP (0x03U) /* use AVREFP as test signal */
/*
Format of A/D Converter Trigger Select Register 0 (ADTRGS0)(F13 only)
*/
/* Selection of the operation trigger of the A/D converter when the timer RD0 input capture B/compare match B
interrupt request is generated (ADTRGS00) */
#define _01_AD_TRIGGER_INTTRD0 (0x01U) /* A/D conversion is started when the interrupt request is generated */
/*
Format of A/D Converter Trigger Select Register 1 (ADTRGS1)(F13 only)
*/
/* Selection of the operation trigger of the A/D converter when the timer RJ0 interrupt request is generated (ADTRGS10) */
#define _01_AD_TRIGGER_INTTRJ0 (0x01U) /* A/D conversion is started when the interrupt request is generated */
/***********************************************************************************************************************
Macro definitions
***********************************************************************************************************************/
/* Upper bound (ADUL) value */
#define _FF_AD_ADUL_VALUE (0xFFU)
/* Upper bound (ADLL) value */
#define _00_AD_ADLL_VALUE (0x00U)
/***********************************************************************************************************************
Typedef definitions
***********************************************************************************************************************/
typedef enum
{
ADCHANNEL0, ADCHANNEL1, ADCHANNEL2, ADCHANNEL3, ADCHANNEL4, ADCHANNEL5, ADCHANNEL6,
ADCHANNEL7, ADCHANNEL8, ADCHANNEL9, ADCHANNEL10, ADCHANNEL11, ADCHANNEL12,
ADCHANNEL13, ADCHANNEL14, ADCHANNEL15, ADCHANNEL16, ADCHANNEL17, ADCHANNEL18,
ADCHANNEL19, ADCHANNEL20, ADCHANNEL21, ADCHANNEL22, ADCHANNEL23, ADCHANNEL24 = 24U,
ADCHANNEL25, ADCHANNEL26, ADCHANNEL27, ADCHANNEL28, ADCHANNEL29, ADCHANNEL30,
ADTEMPERSENSOR0 = 128U, ADINTERREFVOLT
} ad_channel_t;
typedef enum
{
ADNORMALINPUT,
ADAVREFM = 2U,
ADAVREFP
} test_channel_t;
/***********************************************************************************************************************
Global functions
***********************************************************************************************************************/
void R_ADC_Create(void);
void R_ADC_Start(void);
void R_ADC_Stop(void);
void R_ADC_Set_OperationOn(void);
void R_ADC_Set_OperationOff(void);
void R_ADC_Get_Result(uint16_t * const buffer);
/* Start user code for function. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#endif

64
r_cg_adc_user.c

@ -0,0 +1,64 @@
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_cg_adc_user.c
* Version : CodeGenerator for RL78/F14 V2.03.07.02 [08 Nov 2021]
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for ADC module.
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_adc.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
#pragma interrupt r_adc_interrupt(vect=INTAD)
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
* Function Name: r_adc_interrupt
* Description : This function is INTAD interrupt service routine.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
static void __near r_adc_interrupt(void)
{
/* Start user code. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
}
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

2
r_cg_cgc.c

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for CGC module.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************

2
r_cg_cgc.h

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for CGC module.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
#ifndef CGC_H

2
r_cg_cgc_user.c

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for CGC module.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************

2
r_cg_macrodriver.h

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements general head file.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
#ifndef STATUS_H

63
r_cg_port.c

@ -0,0 +1,63 @@
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_cg_port.c
* Version : CodeGenerator for RL78/F14 V2.03.07.02 [08 Nov 2021]
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for PORT module.
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_port.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
* Function Name: R_PORT_Create
* Description : This function initializes the Port I/O.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_PORT_Create(void)
{
P13 = _00_Pn0_OUTPUT_0;
POM6 = _04_POMn2_NCH_ON | _08_POMn3_NCH_ON;
}
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

265
r_cg_port.h

@ -0,0 +1,265 @@
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_cg_port.h
* Version : CodeGenerator for RL78/F14 V2.03.07.02 [08 Nov 2021]
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for PORT module.
* Creation Date: 2026-01-13
***********************************************************************************************************************/
#ifndef PORT_H
#define PORT_H
/***********************************************************************************************************************
Macro definitions (Register bit)
***********************************************************************************************************************/
/*
Port Mode Register (PMm)
*/
/* Pmn pin I/O mode selection (PMm7 - PMm0) */
#define _01_PMn0_NOT_USE (0x01U) /* not use Pn0 as digital I/O */
#define _01_PMn0_MODE_INPUT (0x01U) /* use Pn0 as input mode */
#define _00_PMn0_MODE_OUTPUT (0x00U) /* use Pn0 as output mode */
#define _02_PMn1_NOT_USE (0x02U) /* not use Pn1 as digital I/O */
#define _02_PMn1_MODE_INPUT (0x02U) /* use Pn1 as input mode */
#define _00_PMn1_MODE_OUTPUT (0x00U) /* use Pn1 as output mode */
#define _04_PMn2_NOT_USE (0x04U) /* not use Pn2 as digital I/O */
#define _04_PMn2_MODE_INPUT (0x04U) /* use Pn2 as input mode */
#define _00_PMn2_MODE_OUTPUT (0x00U) /* use Pn2 as output mode */
#define _08_PMn3_NOT_USE (0x08U) /* not use Pn3 as digital I/O */
#define _08_PMn3_MODE_INPUT (0x08U) /* use Pn3 as input mode */
#define _00_PMn3_MODE_OUTPUT (0x00U) /* use Pn3 as output mode */
#define _10_PMn4_NOT_USE (0x10U) /* not use Pn4 as digital I/O */
#define _10_PMn4_MODE_INPUT (0x10U) /* use Pn4 as input mode */
#define _00_PMn4_MODE_OUTPUT (0x00U) /* use Pn4 as output mode */
#define _20_PMn5_NOT_USE (0x20U) /* not use Pn5 as digital I/O */
#define _20_PMn5_MODE_INPUT (0x20U) /* use Pn5 as input mode */
#define _00_PMn5_MODE_OUTPUT (0x00U) /* use Pn5 as output mode */
#define _40_PMn6_NOT_USE (0x40U) /* not use Pn6 as digital I/O */
#define _40_PMn6_MODE_INPUT (0x40U) /* use Pn6 as input mode */
#define _00_PMn6_MODE_OUTPUT (0x00U) /* use Pn6 as output mode */
#define _80_PMn7_NOT_USE (0x80U) /* not use Pn7 as digital I/O */
#define _80_PMn7_MODE_INPUT (0x80U) /* use Pn7 as input mode */
#define _00_PMn7_MODE_OUTPUT (0x00U) /* use Pn7 as output mode */
/*
Port Register (Pm)
*/
/* Pmn pin data (Pm0 to Pm7) */
#define _00_Pn0_OUTPUT_0 (0x00U) /* Pn0 output 0 */
#define _01_Pn0_OUTPUT_1 (0x01U) /* Pn0 output 1 */
#define _00_Pn1_OUTPUT_0 (0x00U) /* Pn1 output 0 */
#define _02_Pn1_OUTPUT_1 (0x02U) /* Pn1 output 1 */
#define _00_Pn2_OUTPUT_0 (0x00U) /* Pn2 output 0 */
#define _04_Pn2_OUTPUT_1 (0x04U) /* Pn2 output 1 */
#define _00_Pn3_OUTPUT_0 (0x00U) /* Pn3 output 0 */
#define _08_Pn3_OUTPUT_1 (0x08U) /* Pn3 output 1 */
#define _00_Pn4_OUTPUT_0 (0x00U) /* Pn4 output 0 */
#define _10_Pn4_OUTPUT_1 (0x10U) /* Pn4 output 1 */
#define _00_Pn5_OUTPUT_0 (0x00U) /* Pn5 output 0 */
#define _20_Pn5_OUTPUT_1 (0x20U) /* Pn5 output 1 */
#define _00_Pn6_OUTPUT_0 (0x00U) /* Pn6 output 0 */
#define _40_Pn6_OUTPUT_1 (0x40U) /* Pn6 output 1 */
#define _00_Pn7_OUTPUT_0 (0x00U) /* Pn7 output 0 */
#define _80_Pn7_OUTPUT_1 (0x80U) /* Pn7 output 1 */
/*
Pull-up Resistor Option Register (PUm)
*/
/* Pmn pin on-chip pull-up resistor selection (PUmn) */
#define _00_PUn0_PULLUP_OFF (0x00U) /* Pn0 pull-up resistor not connected */
#define _01_PUn0_PULLUP_ON (0x01U) /* Pn0 pull-up resistor connected */
#define _00_PUn1_PULLUP_OFF (0x00U) /* Pn1 pull-up resistor not connected */
#define _02_PUn1_PULLUP_ON (0x02U) /* Pn1 pull-up resistor connected */
#define _00_PUn2_PULLUP_OFF (0x00U) /* Pn2 Pull-up resistor not connected */
#define _04_PUn2_PULLUP_ON (0x04U) /* Pn2 pull-up resistor connected */
#define _00_PUn3_PULLUP_OFF (0x00U) /* Pn3 pull-up resistor not connected */
#define _08_PUn3_PULLUP_ON (0x08U) /* Pn3 pull-up resistor connected */
#define _00_PUn4_PULLUP_OFF (0x00U) /* Pn4 pull-up resistor not connected */
#define _10_PUn4_PULLUP_ON (0x10U) /* Pn4 pull-up resistor connected */
#define _00_PUn5_PULLUP_OFF (0x00U) /* Pn5 pull-up resistor not connected */
#define _20_PUn5_PULLUP_ON (0x20U) /* Pn5 pull-up resistor connected */
#define _00_PUn6_PULLUP_OFF (0x00U) /* Pn6 pull-up resistor not connected */
#define _40_PUn6_PULLUP_ON (0x40U) /* Pn6 pull-up resistor connected */
#define _00_PUn7_PULLUP_OFF (0x00U) /* Pn7 pull-up resistor not connected */
#define _80_PUn7_PULLUP_ON (0x80U) /* Pn7 pull-up resistor connected */
/*
Port Input Mode Register (PIMm)
*/
/* Pmn pin input buffer selection (PIMmn) */
#define _00_PIMn0_TTL_OFF (0x00U) /* set Pn0 normal input buffer */
#define _01_PIMn0_TTL_ON (0x01U) /* set Pn0 TTL input buffer */
#define _00_PIMn1_TTL_OFF (0x00U) /* set Pn1 normal input buffer */
#define _02_PIMn1_TTL_ON (0x02U) /* set Pn1 TTL input buffer */
#define _00_PIMn2_TTL_OFF (0x00U) /* set Pn2 normal input buffer */
#define _04_PIMn2_TTL_ON (0x04U) /* set Pn2 TTL input buffer */
#define _00_PIMn3_TTL_OFF (0x00U) /* set Pn3 normal input buffer */
#define _08_PIMn3_TTL_ON (0x08U) /* set Pn3 TTL input buffer */
#define _00_PIMn4_TTL_OFF (0x00U) /* set Pn4 normal input buffer */
#define _10_PIMn4_TTL_ON (0x10U) /* set Pn4 TTL input buffer */
#define _00_PIMn5_TTL_OFF (0x00U) /* set Pn5 normal input buffer */
#define _20_PIMn5_TTL_ON (0x20U) /* set Pn5 TTL input buffer */
#define _00_PIMn6_TTL_OFF (0x00U) /* set Pn6 normal input buffer */
#define _40_PIMn6_TTL_ON (0x40U) /* set Pn6 TTL input buffer */
#define _00_PIMn7_TTL_OFF (0x00U) /* set Pn7 normal input buffer */
#define _80_PIMn7_TTL_ON (0x80U) /* set Pn7 TTL input buffer */
/*
Port Input Threshold Control Register (PITHLm)
*/
/* Pmn pin input threshold selection (PITHLmn) */
#define _00_PITHLn0_SCHMITT3_OFF (0x00U) /* set Pn0 schmitt 1 input (default) */
#define _01_PITHLn0_SCHMITT3_ON (0x01U) /* set Pn0 schmitt 3 input */
#define _00_PITHLn1_SCHMITT3_OFF (0x00U) /* set Pn1 schmitt 1 input (default) */
#define _02_PITHLn1_SCHMITT3_ON (0x02U) /* set Pn1 schmitt 3 input */
#define _00_PITHLn2_SCHMITT3_OFF (0x00U) /* set Pn2 schmitt 1 input (default) */
#define _04_PITHLn2_SCHMITT3_ON (0x04U) /* set Pn2 schmitt 3 input */
#define _00_PITHLn3_SCHMITT3_OFF (0x00U) /* set Pn3 schmitt 1 input (default) */
#define _08_PITHLn3_SCHMITT3_ON (0x08U) /* set Pn3 schmitt 3 input */
#define _00_PITHLn4_SCHMITT3_OFF (0x00U) /* set Pn4 schmitt 1 input (default) */
#define _10_PITHLn4_SCHMITT3_ON (0x10U) /* set Pn4 schmitt 3 input */
#define _00_PITHLn5_SCHMITT3_OFF (0x00U) /* set Pn5 schmitt 1 input (default) */
#define _20_PITHLn5_SCHMITT3_ON (0x20U) /* set Pn5 schmitt 3 input */
#define _00_PITHLn6_SCHMITT3_OFF (0x00U) /* set Pn6 schmitt 1 input (default) */
#define _40_PITHLn6_SCHMITT3_ON (0x40U) /* set Pn6 schmitt 3 input */
#define _00_PITHLn7_SCHMITT3_OFF (0x00U) /* set Pn7 schmitt 1 input (default) */
#define _80_PITHLn7_SCHMITT3_ON (0x80U) /* set Pn7 schmitt 3 input */
/*
Port Output Mode Register (POMm)
*/
/* Pmn pin output mode selection (POMmn) */
#define _00_POMn0_NCH_OFF (0x00U) /* set Pn0 output normal mode */
#define _01_POMn0_NCH_ON (0x01U) /* set Pn0 output N-ch open-drain mode */
#define _00_POMn1_NCH_OFF (0x00U) /* set Pn1 output normal mode */
#define _02_POMn1_NCH_ON (0x02U) /* set Pn1 output N-ch open-drain mode */
#define _00_POMn2_NCH_OFF (0x00U) /* set Pn2 output normal mode */
#define _04_POMn2_NCH_ON (0x04U) /* set Pn2 output N-ch open-drain mode */
#define _00_POMn3_NCH_OFF (0x00U) /* set Pn3 output normal mode */
#define _08_POMn3_NCH_ON (0x08U) /* set Pn3 output N-ch open-drain mode */
#define _00_POMn4_NCH_OFF (0x00U) /* set Pn4 output normal mode */
#define _10_POMn4_NCH_ON (0x10U) /* set Pn4 output N-ch open-drain mode */
#define _00_POMn5_NCH_OFF (0x00U) /* set Pn5 output normal mode */
#define _20_POMn5_NCH_ON (0x20U) /* set Pn5 output N-ch open-drain mode */
#define _00_POMn6_NCH_OFF (0x00U) /* set Pn6 output normal mode */
#define _40_POMn6_NCH_ON (0x40U) /* set Pn6 output N-ch open-drain mode */
#define _00_POMn7_NCH_OFF (0x00U) /* set Pn7 output normal mode */
#define _80_POMn7_NCH_ON (0x80U) /* set Pn7 output N-ch open-drain mode */
/*
Port Operation Mode Register (PMCm)
*/
/* Pmn pin digital input buffer selection (PMCmn) */
#define _01_PMCn0_NOT_USE (0x01U) /* not use Pn0 digital input */
#define _00_PMCn0_DI_ON (0x00U) /* enable Pn0 digital input */
#define _02_PMCn1_NOT_USE (0x02U) /* not use Pn1 digital input */
#define _00_PMCn1_DI_ON (0x00U) /* enable Pn1 digital input */
#define _04_PMCn2_NOT_USE (0x04U) /* not use Pn2 digital input */
#define _00_PMCn2_DI_ON (0x00U) /* enable Pn2 digital input */
#define _08_PMCn3_NOT_USE (0x08U) /* not use Pn3 digital input */
#define _00_PMCn3_DI_ON (0x00U) /* enable Pn3 digital input */
#define _10_PMCn4_NOT_USE (0x10U) /* not use Pn4 digital input */
#define _00_PMCn4_DI_ON (0x00U) /* enable Pn4 digital input */
#define _20_PMCn5_NOT_USE (0x20U) /* not use Pn5 digital input */
#define _00_PMCn5_DI_ON (0x00U) /* enable Pn5 digital input */
#define _40_PMCn6_NOT_USE (0x40U) /* not use Pn6 digital input */
#define _00_PMCn6_DI_ON (0x00U) /* enable Pn6 digital input */
#define _80_PMCn7_NOT_USE (0x80U) /* not use Pn7 digital input */
#define _00_PMCn7_DI_ON (0x00U) /* enable Pn7 digital input */
/*
Port output slew rate select register (PSRSEL)
*/
/* P140/PCLBUZ0 pin output mode selection (PSR140) */
#define _00_PSR140_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
#define _20_PSR140_SLOW (0x20U) /* slow mode (25 V/5 ns (target) (TYP.)) */
/* P14/SCK01/SCL01/TO06/TRDIOC0 pin output mode selection (PSR14) */
#define _00_PSR14_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
#define _10_PSR14_SLOW (0x10U) /* slow mode (25 V/5 ns (target) (TYP.)) */
/* P120/SO01/TO07/TRDIOD0 pin output mode selection (PSR120) */
#define _00_PSR120_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
#define _08_PSR120_SLOW (0x08U) /* slow mode (25 V/5 ns (target) (TYP.)) */
/* P30/TO01/TRDIOD1/SNZOUT0 pin output mode selection (PSR30) */
#define _00_PSR30_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
#define _04_PSR30_SLOW (0x04U) /* slow mode (25 V/5 ns (target) (TYP.)) */
/* P12/SO10/TO11/(TRDIOD0)/TXD1/SNZOUT3 pin output mode selection (PSR12) */
#define _00_PSR12_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
#define _02_PSR12_SLOW (0x02U) /* slow mode (25 V/5 ns (target) (TYP.)) */
/* P10/SCK10/TO13/TRJO0/SCL10/LTXD1/CTXD0 pin output mode selection (PSR10) */
#define _00_PSR10_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
#define _01_PSR10_SLOW (0x01U) /* slow mode (25 V/5 ns (target) (TYP.)) */
/*
AD port configuration register (ADPC)
*/
/* Analog input/digital input switching (ADPC4 - ADPC0) */
#define _00_ADPC_DI_OFF (0x00U) /* use P33, P34, P80 - P87, P90 - P97, P100 - P105 as analog input */
#define _18_ADPC_DI_ON (0x18U) /* use P105 as digital input */
#define _17_ADPC_DI_ON (0x17U) /* use P104 - P105 as digital input */
#define _16_ADPC_DI_ON (0x16U) /* use P103 - P105 as digital input */
#define _15_ADPC_DI_ON (0x15U) /* use P102 - P105 as digital input */
#define _14_ADPC_DI_ON (0x14U) /* use P101 - P105 as digital input */
#define _13_ADPC_DI_ON (0x13U) /* use P100 - P105 as digital input */
#define _12_ADPC_DI_ON (0x12U) /* use P97, P100 - P105 as digital input */
#define _11_ADPC_DI_ON (0x11U) /* use P96 - P97, P100 - P105 as digital input */
#define _10_ADPC_DI_ON (0x10U) /* use P95 - P97, P100 - P105 as digital input */
#define _0F_ADPC_DI_ON (0x0FU) /* use P94 - P97, P100 - P105 as digital input */
#define _0E_ADPC_DI_ON (0x0EU) /* use P93 - P97, P100 - P105 as digital input */
#define _0D_ADPC_DI_ON (0x0DU) /* use P92 - P97, P100 - P105 as digital input */
#define _0C_ADPC_DI_ON (0x0CU) /* use P91 - P97, P100 - P105 as digital input */
#define _0B_ADPC_DI_ON (0x0BU) /* use P90 - P97, P100 - P105 as digital input */
#define _0A_ADPC_DI_ON (0x0AU) /* use P87, P90 - P97, P100 - P105 as digital input */
#define _09_ADPC_DI_ON (0x09U) /* use P86 - P87, P90 - P97, P100 - P105 as digital input */
#define _08_ADPC_DI_ON (0x08U) /* use P85 - P87, P90 - P97, P100 - P105 as digital input */
#define _07_ADPC_DI_ON (0x07U) /* use P84 - P87, P90 - P97, P100 - P105 as digital input */
#define _06_ADPC_DI_ON (0x06U) /* use P83 - P87, P90 - P97, P100 - P105 as digital input */
#define _05_ADPC_DI_ON (0x05U) /* use P82 - P87, P90 - P97, P100 - P105 as digital input */
#define _04_ADPC_DI_ON (0x04U) /* use P81 - P87, P90 - P97, P100 - P105 as digital input */
#define _03_ADPC_DI_ON (0x03U) /* use P80 - P87, P90 - P97, P100 - P105 as digital input */
#define _02_ADPC_DI_ON (0x02U) /* use P34, P80 - P87, P90 - P97, P100 - P105 as digital input */
#define _01_ADPC_DI_ON (0x01U) /* use P33, P34, P80 - P87, P90 - P97, P100 - P105 as digital input */
/***********************************************************************************************************************
Macro definitions
***********************************************************************************************************************/
#define _F0_PM0_DEFAULT (0xF0U) /* PM0 default value */
#define _E0_PM3_DEFAULT (0xE0U) /* PM3 default value */
#define _1E_PM12_DEFAULT (0x1EU) /* PM12 default value */
#define _FE_PM14_DEFAULT (0xFEU) /* PM14 default value */
#define _E0_PMC7_DEFAULT (0xE0U) /* PMC7 default value */
#define _DE_PMC12_DEFAULT (0xDEU) /* PMC12 default value */
/***********************************************************************************************************************
Typedef definitions
***********************************************************************************************************************/
/***********************************************************************************************************************
Global functions
***********************************************************************************************************************/
void R_PORT_Create(void);
/* Start user code for function. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#endif

51
r_cg_port_user.c

@ -0,0 +1,51 @@
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_cg_port_user.c
* Version : CodeGenerator for RL78/F14 V2.03.07.02 [08 Nov 2021]
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for PORT module.
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_port.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

187
r_cg_serial.c

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for Serial module.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************
@ -54,6 +54,13 @@ volatile uint16_t g_uart1_tx_count; /* uart1 transmit data number */
volatile uint8_t * gp_uart1_rx_address; /* uart1 receive buffer address */
volatile uint16_t g_uart1_rx_count; /* uart1 receive data number */
volatile uint16_t g_uart1_rx_length; /* uart1 receive data length */
volatile uint8_t g_iica0_master_status_flag; /* iica0 master flag */
volatile uint8_t g_iica0_slave_status_flag; /* iica0 slave flag */
volatile uint8_t * gp_iica0_rx_address; /* iica0 receive buffer address */
volatile uint16_t g_iica0_rx_len; /* iica0 receive data length */
volatile uint16_t g_iica0_rx_cnt; /* iica0 receive data count */
volatile uint8_t * gp_iica0_tx_address; /* iica0 send buffer address */
volatile uint16_t g_iica0_tx_cnt; /* iica0 send data count */
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
@ -70,7 +77,7 @@ void R_SAU0_Create(void)
NOP();
NOP();
NOP();
SPS0 = _0000_SAU_CK00_FCLK_0 | _0040_SAU_CK01_FCLK_4;
SPS0 = _0000_SAU_CK00_FCLK_0 | _0000_SAU_CK01_FCLK_0;
R_UART0_Create();
}
@ -93,16 +100,16 @@ void R_UART0_Create(void)
/* Set INTSR0 low priority */
SRPR10 = 1U;
SRPR00 = 1U;
SMR00 = _0020_SAU_SMRMN_INITIALVALUE | _8000_SAU_CLOCK_SELECT_CK01 | _0000_SAU_TRIGGER_SOFTWARE |
SMR00 = _0020_SAU_SMRMN_INITIALVALUE | _0000_SAU_CLOCK_SELECT_CK00 | _0000_SAU_TRIGGER_SOFTWARE |
_0002_SAU_MODE_UART | _0000_SAU_TRANSFER_END;
SCR00 = _8000_SAU_TRANSMISSION | _0000_SAU_PARITY_NONE | _0080_SAU_LSB | _0010_SAU_STOP_1 | _0007_SAU_LENGTH_8;
SDR00 = _CE00_UART0_TRANSMIT_DIVISOR;
SDR00 = _4400_UART0_TRANSMIT_DIVISOR;
NFEN0 |= _01_SAU_RXD0_FILTER_ON;
SIR01 = _0004_SAU_SIRMN_FECTMN | _0002_SAU_SIRMN_PECTMN | _0001_SAU_SIRMN_OVCTMN; /* clear error flag */
SMR01 = _0020_SAU_SMRMN_INITIALVALUE | _0000_SAU_CLOCK_SELECT_CK00 | _0100_SAU_TRIGGER_RXD | _0000_SAU_EDGE_FALL |
_0002_SAU_MODE_UART | _0000_SAU_TRANSFER_END;
SCR01 = _4000_SAU_RECEPTION | _0000_SAU_PARITY_NONE | _0080_SAU_LSB | _0010_SAU_STOP_1 | _0007_SAU_LENGTH_8;
SDR01 = _2000_UART0_RECEIVE_DIVISOR;
SDR01 = _4400_UART0_RECEIVE_DIVISOR;
SO0 |= _0001_SAU_CH0_DATA_OUTPUT_1;
SOL0 |= _0000_SAU_CHANNEL0_NORMAL; /* output level normal */
SOE0 |= _0001_SAU_CH0_OUTPUT_ENABLE; /* enable UART0 output */
@ -219,7 +226,7 @@ void R_SAU1_Create(void)
NOP();
NOP();
NOP();
SPS1 = _0004_SAU_CK00_FCLK_4 | _0040_SAU_CK01_FCLK_4;
SPS1 = _0000_SAU_CK00_FCLK_0 | _0000_SAU_CK01_FCLK_0;
R_UART1_Create();
}
@ -245,13 +252,13 @@ void R_UART1_Create(void)
SMR10 = _0020_SAU_SMRMN_INITIALVALUE | _0000_SAU_CLOCK_SELECT_CK00 | _0000_SAU_TRIGGER_SOFTWARE |
_0002_SAU_MODE_UART | _0000_SAU_TRANSFER_END;
SCR10 = _8000_SAU_TRANSMISSION | _0000_SAU_PARITY_NONE | _0080_SAU_LSB | _0010_SAU_STOP_1 | _0007_SAU_LENGTH_8;
SDR10 = _CE00_UART1_TRANSMIT_DIVISOR;
SDR10 = _4400_UART1_TRANSMIT_DIVISOR;
NFEN0 |= _04_SAU_RXD1_FILTER_ON;
SIR11 = _0004_SAU_SIRMN_FECTMN | _0002_SAU_SIRMN_PECTMN | _0001_SAU_SIRMN_OVCTMN; /* clear error flag */
SMR11 = _0020_SAU_SMRMN_INITIALVALUE | _0000_SAU_CLOCK_SELECT_CK00 | _0100_SAU_TRIGGER_RXD | _0000_SAU_EDGE_FALL |
_0002_SAU_MODE_UART | _0000_SAU_TRANSFER_END;
SCR11 = _4000_SAU_RECEPTION | _0000_SAU_PARITY_NONE | _0080_SAU_LSB | _0010_SAU_STOP_1 | _0007_SAU_LENGTH_8;
SDR11 = _CE00_UART1_RECEIVE_DIVISOR;
SDR11 = _4400_UART1_RECEIVE_DIVISOR;
SO1 |= _0001_SAU_CH0_DATA_OUTPUT_1;
SOL1 |= _0000_SAU_CHANNEL0_NORMAL; /* output level normal */
SOE1 |= _0001_SAU_CH0_OUTPUT_ENABLE; /* enable UART1 output */
@ -355,5 +362,169 @@ MD_STATUS R_UART1_Send(uint8_t * const tx_buf, uint16_t tx_num)
return (status);
}
/***********************************************************************************************************************
* Function Name: R_IICA0_Create
* Description : This function initializes the IICA0 module.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_IICA0_Create(void)
{
IICA0EN = 1U; /* supply IICA0 clock */
IICE0 = 0U; /* disable IICA0 operation */
IICAMK0 = 1U; /* disable INTIICA0 interrupt */
IICAIF0 = 0U; /* clear INTIICA0 interrupt flag */
/* Set INTIICA0 low priority */
IICAPR10 = 1U;
IICAPR00 = 1U;
/* Set SCLA0, SDAA0 pin */
P6 &= 0xF3U;
PM6 |= 0x0CU;
SMC0 = 0U;
IICWL0 = _4C_IICA0_IICWL_VALUE;
IICWH0 = _55_IICA0_IICWH_VALUE;
IICCTL01 |= _01_IICA_fCLK_HALF;
SVA0 = _10_IICA0_MASTERADDRESS;
STCEN0 = 1U;
IICRSV0 = 1U;
SPIE0 = 0U;
WTIM0 = 1U;
ACKE0 = 1U;
IICAMK0 = 0U;
IICE0 = 1U;
LREL0 = 1U;
/* Set SCLA0, SDAA0 pin */
PM6 &= 0xF3U;
}
/***********************************************************************************************************************
* Function Name: R_IICA0_Stop
* Description : This function stops IICA0 module operation.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_IICA0_Stop(void)
{
IICE0 = 0U; /* disable IICA0 operation */
}
/***********************************************************************************************************************
* Function Name: R_IICA0_StopCondition
* Description : This function sets IICA0 stop condition flag.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_IICA0_StopCondition(void)
{
SPT0 = 1U; /* set stop condition flag */
}
/***********************************************************************************************************************
* Function Name: R_IICA0_Master_Send
* Description : This function starts to send data as master mode.
* Arguments : adr -
* send address
* tx_buf -
* transfer buffer pointer
* tx_num -
* buffer size
* wait -
* wait for start condition
* Return Value : status -
* MD_OK or MD_ERROR1 or MD_ERROR2
***********************************************************************************************************************/
MD_STATUS R_IICA0_Master_Send(uint8_t adr, uint8_t * const tx_buf, uint16_t tx_num, uint8_t wait)
{
MD_STATUS status = MD_OK;
IICAMK0 = 1U; /* disable INTIICA0 interrupt */
if ((1U == IICBSY0) && (0U == MSTS0))
{
/* Check bus busy */
IICAMK0 = 0U; /* enable INTIICA0 interrupt */
status = MD_ERROR1;
}
else
{
STT0 = 1U; /* send IICA0 start condition */
IICAMK0 = 0U; /* enable INTIICA0 interrupt */
/* Wait */
while (wait--)
{
;
}
if (0U == STD0)
{
status = MD_ERROR2;
}
/* Set parameter */
g_iica0_tx_cnt = tx_num;
gp_iica0_tx_address = tx_buf;
g_iica0_master_status_flag = _00_IICA_MASTER_FLAG_CLEAR;
adr &= (uint8_t)~0x01U; /* set send mode */
IICA0 = adr; /* send address */
}
return (status);
}
/***********************************************************************************************************************
* Function Name: R_IICA0_Master_Receive
* Description : This function starts to receive IICA0 data as master mode.
* Arguments : adr -
* receive address
* rx_buf -
* receive buffer pointer
* rx_num -
* buffer size
* wait -
* wait for start condition
* Return Value : status -
* MD_OK or MD_ERROR1 or MD_ERROR2
***********************************************************************************************************************/
MD_STATUS R_IICA0_Master_Receive(uint8_t adr, uint8_t * const rx_buf, uint16_t rx_num, uint8_t wait)
{
MD_STATUS status = MD_OK;
IICAMK0 = 1U; /* disable INTIIA0 interrupt */
if ((1U == IICBSY0) && (0U == MSTS0))
{
/* Check bus busy */
IICAMK0 = 0U; /* enable INTIIA0 interrupt */
status = MD_ERROR1;
}
else
{
STT0 = 1U; /* set IICA0 start condition */
IICAMK0 = 0U; /* enable INTIIA0 interrupt */
/* Wait */
while (wait--)
{
;
}
if (0U == STD0)
{
status = MD_ERROR2;
}
/* Set parameter */
g_iica0_rx_len = rx_num;
g_iica0_rx_cnt = 0U;
gp_iica0_rx_address = rx_buf;
g_iica0_master_status_flag = _00_IICA_MASTER_FLAG_CLEAR;
adr |= 0x01U; /* set receive mode */
IICA0 = adr; /* receive address */
}
return (status);
}
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

23
r_cg_serial.h

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for Serial module.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
#ifndef SERIAL_H
@ -348,10 +348,13 @@ Macro definitions (Register bit)
/***********************************************************************************************************************
Macro definitions
***********************************************************************************************************************/
#define _2000_UART0_RECEIVE_DIVISOR (0x2000U)
#define _CE00_UART0_TRANSMIT_DIVISOR (0xCE00U)
#define _CE00_UART1_RECEIVE_DIVISOR (0xCE00U)
#define _CE00_UART1_TRANSMIT_DIVISOR (0xCE00U)
#define _4400_UART0_RECEIVE_DIVISOR (0x4400U)
#define _4400_UART0_TRANSMIT_DIVISOR (0x4400U)
#define _4400_UART1_RECEIVE_DIVISOR (0x4400U)
#define _4400_UART1_TRANSMIT_DIVISOR (0x4400U)
#define _10_IICA0_MASTERADDRESS (0x10U)
#define _55_IICA0_IICWH_VALUE (0x55U)
#define _4C_IICA0_IICWL_VALUE (0x4CU)
/***********************************************************************************************************************
Typedef definitions
@ -380,6 +383,16 @@ static void r_uart1_callback_error(uint8_t err_type);
static void r_uart1_callback_receiveend(void);
static void r_uart1_callback_sendend(void);
static void r_uart1_callback_softwareoverrun(uint16_t rx_data);
void R_IICA0_Create(void);
MD_STATUS R_IICA0_Master_Send(uint8_t adr, uint8_t * const tx_buf, uint16_t tx_num, uint8_t wait);
MD_STATUS R_IICA0_Master_Receive(uint8_t adr, uint8_t * const rx_buf, uint16_t rx_num, uint8_t wait);
void R_IICA0_Stop(void);
void R_IICA0_StopCondition(void);
static void r_iica0_callback_master_sendend(void);
static void r_iica0_callback_master_receiveend(void);
static void r_iica0_callback_master_error(MD_STATUS flag);
static void iica0_masterhandler(void);
static void iica0_slavehandler(void);
/* Start user code for function. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

181
r_cg_serial_user.c

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for Serial module.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************
@ -32,6 +32,7 @@ Includes
#include "r_cg_macrodriver.h"
#include "r_cg_serial.h"
/* Start user code for include. Do not edit comment generated here */
#include "uart.h"
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
@ -42,6 +43,7 @@ Pragma directive
#pragma interrupt r_uart0_interrupt_receive(vect=INTSR0)
#pragma interrupt r_uart1_interrupt_send(vect=INTST1)
#pragma interrupt r_uart1_interrupt_receive(vect=INTSR1)
#pragma interrupt r_iica0_interrupt(vect=INTIICA0)
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
@ -58,6 +60,13 @@ extern volatile uint16_t g_uart1_tx_count; /* uart1 send data number
extern volatile uint8_t * gp_uart1_rx_address; /* uart1 receive buffer address */
extern volatile uint16_t g_uart1_rx_count; /* uart1 receive data number */
extern volatile uint16_t g_uart1_rx_length; /* uart1 receive data length */
extern volatile uint8_t g_iica0_master_status_flag; /* iica0 master flag */
extern volatile uint8_t g_iica0_slave_status_flag; /* iica0 slave flag */
extern volatile uint8_t * gp_iica0_rx_address; /* iica0 receive buffer address */
extern volatile uint16_t g_iica0_rx_cnt; /* iica0 receive data length */
extern volatile uint16_t g_iica0_rx_len; /* iica0 receive data count */
extern volatile uint8_t * gp_iica0_tx_address; /* iica0 send buffer address */
extern volatile uint16_t g_iica0_tx_cnt; /* iica0 send data count */
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
@ -153,6 +162,7 @@ static void r_uart0_callback_softwareoverrun(uint16_t rx_data)
static void r_uart0_callback_sendend(void)
{
/* Start user code. Do not edit comment generated here */
rs485_set_tx(0);
/* End user code. Do not edit comment generated here */
}
@ -236,6 +246,22 @@ static void __near r_uart1_interrupt_send(void)
static void r_uart1_callback_receiveend(void)
{
/* Start user code. Do not edit comment generated here */
uint8_t c = uart_rx_buffer[uart_rx_index];
uart_rx_index++;
uart_rx_length = uart_rx_index;
// 한 줄 입력 끝 or 버퍼 가득
if (c == '\n' || uart_rx_index >= (UART_RX_BUF_SIZE - 1))
{
uart_rx_done = 1;
}
else
{
// 다음 1바이트 계속 수신
R_UART1_Receive((uint8_t *)&uart_rx_buffer[uart_rx_index], 1);
}
/* End user code. Do not edit comment generated here */
}
@ -277,5 +303,158 @@ static void r_uart1_callback_error(uint8_t err_type)
/* End user code. Do not edit comment generated here */
}
/***********************************************************************************************************************
* Function Name: r_iica0_interrupt
* Description : This function is INTIICA0 interrupt service routine.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
static void __near r_iica0_interrupt(void)
{
if ((IICS0 & _80_IICA_STATUS_MASTER) == 0x80U)
{
iica0_masterhandler();
}
}
/***********************************************************************************************************************
* Function Name: iica0_masterhandler
* Description : This function is IICA0 master handler.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
static void iica0_masterhandler(void)
{
/* Detection of stop condition handling */
if ((0U == IICBSY0) && (g_iica0_tx_cnt != 0U))
{
r_iica0_callback_master_error(MD_SPT);
}
else
{
/* Control for sended address */
if ((g_iica0_master_status_flag & _80_IICA_ADDRESS_COMPLETE) == 0U)
{
if (1U == ACKD0)
{
g_iica0_master_status_flag |= _80_IICA_ADDRESS_COMPLETE;
if (1U == TRC0)
{
WTIM0 = 1U;
if (g_iica0_tx_cnt > 0U)
{
IICA0 = *gp_iica0_tx_address;
gp_iica0_tx_address++;
g_iica0_tx_cnt--;
}
else
{
r_iica0_callback_master_sendend();
}
}
else
{
ACKE0 = 1U;
WTIM0 = 0U;
WREL0 = 1U;
}
}
else
{
r_iica0_callback_master_error(MD_NACK);
}
}
else
{
/* Master send control */
if (1U == TRC0)
{
if ((0U == ACKD0) && (g_iica0_tx_cnt != 0U))
{
r_iica0_callback_master_error(MD_NACK);
}
else
{
if (g_iica0_tx_cnt > 0U)
{
IICA0 = *gp_iica0_tx_address;
gp_iica0_tx_address++;
g_iica0_tx_cnt--;
}
else
{
r_iica0_callback_master_sendend();
}
}
}
/* Master receive control */
else
{
if (g_iica0_rx_cnt < g_iica0_rx_len)
{
*gp_iica0_rx_address = IICA0;
gp_iica0_rx_address++;
g_iica0_rx_cnt++;
if (g_iica0_rx_cnt == g_iica0_rx_len)
{
ACKE0 = 0U;
WTIM0 = 1U;
WREL0 = 1U;
}
else
{
WREL0 = 1U;
}
}
else
{
r_iica0_callback_master_receiveend();
}
}
}
}
}
/***********************************************************************************************************************
* Function Name: r_iica0_callback_master_error
* Description : This function is a callback function when IICA0 master error occurs.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
static void r_iica0_callback_master_error(MD_STATUS flag)
{
/* Start user code. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
}
/***********************************************************************************************************************
* Function Name: r_iica0_callback_master_receiveend
* Description : This function is a callback function when IICA0 finishes master reception.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
static void r_iica0_callback_master_receiveend(void)
{
SPT0 = 1U;
/* Start user code. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
}
/***********************************************************************************************************************
* Function Name: r_iica0_callback_master_sendend
* Description : This function is a callback function when IICA0 finishes master transmission.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
static void r_iica0_callback_master_sendend(void)
{
SPT0 = 1U;
/* Start user code. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
}
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

2
r_cg_userdefine.h

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file includes user definition.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
#ifndef _USER_DEF_H

2
r_cg_wdt.c

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for WDT module.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************

2
r_cg_wdt.h

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for WDT module.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
#ifndef WDT_H

2
r_cg_wdt_user.c

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements device driver for WDT module.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************

360
r_main.c

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements main function.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************
@ -31,37 +31,28 @@ Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_cgc.h"
#include "r_cg_port.h"
#include "r_cg_serial.h"
#include "r_cg_adc.h"
#include "r_cg_wdt.h"
/* Start user code for include. Do not edit comment generated here */
#include "common.h"
#include "r_cg_macrodriver.h"
#include "anaout.h"
#include "dipSwitch.h"
#include <string.h>
#include <ctype.h>
#include <stddef.h>
#include <r_cg_port.h>
#define UART_RX_BUF_SIZE 96
#define CMD_MAX 529
// pin10~13 ↔ P1.0~P1.3 가정
#define X0C_PORT P1
#define X0C_PORTMODE PM1
#define X0C_CH0_MASK _01_Pn0_OUTPUT_1 // P1.0 = 1
#define X0C_CH1_MASK _02_Pn1_OUTPUT_1 // P1.1 = 1
#define X0C_CH2_MASK _04_Pn2_OUTPUT_1 // P1.2 = 1
#define X0C_CH3_MASK _08_Pn3_OUTPUT_1 // P1.3 = 1
#define X0C_MASK (X0C_CH0_MASK|X0C_CH1_MASK|X0C_CH2_MASK|X0C_CH3_MASK)
#define CMD_MAX 529
extern volatile uint8_t uart_rx_done;
extern volatile uint8_t uart_rx_index;
extern volatile uint8_t uart_rx_buffer[UART_RX_BUF_SIZE];
extern volatile uint16_t uart_rx_length;
volatile uint8_t uart_rx_done = 0;
volatile uint8_t uart_rx_index = 0;
volatile uint8_t uart_rx_buffer[UART_RX_BUF_SIZE] = {0};
volatile uint16_t uart_rx_length = 0;
static uint8_t uart0_rx_buffer[11];
const unsigned char *d;
unsigned int len;
// (1~32)
static uint8_t g_fixed_addr = 1;
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
@ -74,44 +65,27 @@ static unsigned char hex2byte(char h, char l)
unsigned char hi, lo;
if (h >= 'a' && h <= 'f') h -= 32;
if (l >= 'a' && l <= 'f') l -= 32;
hi = (h >= 'A') ? h - 'A' + 10 : h - '0';
lo = (l >= 'A') ? l - 'A' + 10 : l - '0';
return (hi << 4) | lo;
}
// === X0C GPIO: P1.0~P1.3 을 pin10~13으로 사용한다고 가정 ===
static void x0c_init(void){
// 출력으로 설정
X0C_PORTMODE &= (uint8_t)~(uint8_t)X0C_MASK;
// 모두 LOW
X0C_PORT &= (uint8_t)~(uint8_t)X0C_MASK;
hi = (h >= 'A') ? (unsigned char)(h - 'A' + 10) : (unsigned char)(h - '0');
lo = (l >= 'A') ? (unsigned char)(l - 'A' + 10) : (unsigned char)(l - '0');
return (unsigned char)((hi << 4) | lo);
}
static void x0c_all_low(void){
X0C_PORT &= (uint8_t)~(uint8_t)X0C_MASK;
}
static void x0c_select(uint8_t ch){
// break-before-make
X0C_PORT &= (uint8_t)~(uint8_t)X0C_MASK;
__nop(); __nop(); __nop(); __nop();
switch(ch){
case 0: X0C_PORT = (uint8_t)((X0C_PORT & (uint8_t)~(uint8_t)X0C_MASK) | X0C_CH0_MASK); break;
case 1: X0C_PORT = (uint8_t)((X0C_PORT & (uint8_t)~(uint8_t)X0C_MASK) | X0C_CH1_MASK); break;
case 2: X0C_PORT = (uint8_t)((X0C_PORT & (uint8_t)~(uint8_t)X0C_MASK) | X0C_CH2_MASK); break;
case 3: X0C_PORT = (uint8_t)((X0C_PORT & (uint8_t)~(uint8_t)X0C_MASK) | X0C_CH3_MASK); break;
default: /* 255=all low 등 */ break;
}
}
typedef void (*CmdHandler)(const unsigned char *data, unsigned int len);
void cmd_unknown(const unsigned char *d, unsigned int len)
// Prefix: "X<AA>C_<CCC>:"
static int parse_x_prefix(const char *s, int len, uint8_t *addr, uint8_t *ch, int *payload_pos)
{
uart_send_string("Unknownaaaaa cmd\r\n");
delay(100000);
if (len < 9) return 0;
if (toupper((unsigned char)s[0]) != 'X') return 0;
if (!isdigit((unsigned char)s[1]) || !isdigit((unsigned char)s[2])) return -1;
if (toupper((unsigned char)s[3]) != 'C') return -1;
if (s[4] != '_') return -1;
if (!isdigit((unsigned char)s[5]) || !isdigit((unsigned char)s[6]) || !isdigit((unsigned char)s[7])) return -1;
if (s[8] != ':') return -1;
*addr = (uint8_t)((s[1] - '0') * 10 + (s[2] - '0'));
*ch = (uint8_t)((s[5] - '0') * 100 + (s[6] - '0') * 10 + (s[7] - '0'));
*payload_pos = 9;
return 1;
}
typedef enum {
@ -129,86 +103,40 @@ typedef enum {
PROTOCOL_UNKNOWN
} ProtocolType;
ProtocolType detect_protocol(char header1,char header2)
static ProtocolType detect_protocol(char header1, char header2)
{
if (header1 == 'I' && header2 == 'W' ) return PROTOCOL_I2CW;
if (header1 == 'I' && header2 == 'W') return PROTOCOL_I2CW;
if (header1 == 'I' && header2 == 'R') return PROTOCOL_I2CR;
if (header1 == 'O' && header2 == 'W' ) return PROTOCOL_OWIW;
if (header1 == 'O' && header2 == 'R' ) return PROTOCOL_OWIR;
if (header1 == 'O' && header2 == 'W') return PROTOCOL_OWIW;
if (header1 == 'O' && header2 == 'R') return PROTOCOL_OWIR;
return PROTOCOL_UNKNOWN;
}
typedef struct {
unsigned char code;
CmdHandler fn;
} CmdMap;
void process_cmd(ProtocolType protocol, uint8_t id/*unsigned char code*/,
const unsigned char *data, unsigned int len)
static void cmd_unknown(const unsigned char *d, unsigned int len)
{
const CmdMap *map = NULL;
int map_size = 0;
int i;
uart1_send_string("Unknown cmd\r\n");
delay(100000);
}
static void process_cmd(ProtocolType protocol, uint8_t id,
const unsigned char *data, unsigned int len)
{
switch (protocol) {
case PROTOCOL_I2CT:
I2C_T_Command_Mode_receiveData(data,(uint8_t)len, id);
break;
case PROTOCOL_OWIT:
OWI_T_CommandMode(data,(uint8_t)len, id);
break;
case PROTOCOL_I2CW:
I2C_Command_Mode_receiveData(data,(uint8_t)len,id);
break;
case PROTOCOL_I2CR:
I2C_Command_Mode_Send((uint8_t)len, id);
break;
case PROTOCOL_OWIW:
OWI_CommandMode(data,(uint8_t)len,id);
break;
case PROTOCOL_OWIR:
OWI_ReadBytesAndPrint(len,id);
break;
case PROTOCOL_I2CA:
I2C_A_Command_Mode_receiveData(data,(uint8_t)len,id);
break;
case PROTOCOL_OWIA:
OWI_A_CommandMode(data,(uint8_t)len,id);
break;
case PROTOCOL_OWID:
OWI_disable();
break;
case PROTOCOL_OWIC:
OWI_Diagnostic(id);
break;
case PROTOCOL_I2CC:
I2C_Diagnostic(id);
break;
default:
cmd_unknown(data, len);
return;
case PROTOCOL_I2CT: I2C_T_Command_Mode_receiveData(data, (uint8_t)len, id); break;
case PROTOCOL_OWIT: OWI_T_CommandMode(data, (uint8_t)len, id); break;
case PROTOCOL_I2CW: I2C_Command_Mode_receiveData(data, (uint8_t)len, id); break;
case PROTOCOL_I2CR: I2C_Command_Mode_Send((uint8_t)len, id); break;
case PROTOCOL_OWIW: OWI_CommandMode(data, (uint8_t)len, id); break;
case PROTOCOL_OWIR: OWI_ReadBytesAndPrint(len, id); break;
case PROTOCOL_I2CA: I2C_A_Command_Mode_receiveData(data, (uint8_t)len, id); break;
case PROTOCOL_OWIA: OWI_A_CommandMode(data, (uint8_t)len, id); break;
case PROTOCOL_OWID: OWI_disable(); break;
case PROTOCOL_OWIC: OWI_Diagnostic(id); break;
case PROTOCOL_I2CC: I2C_Diagnostic(id); break;
default: cmd_unknown(data, len); break;
}
}
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
void handle_uart_command_line(void)
{
char line[UART_RX_BUF_SIZE];
@ -220,7 +148,7 @@ void handle_uart_command_line(void)
int i;
int idx = 0;
int pos = 2;
int rx_len;
int rx_len;
ProtocolType proto;
uint8_t id;
unsigned int byte_len;
@ -233,8 +161,7 @@ void handle_uart_command_line(void)
if (rx_len < 0) rx_len = 0;
if (rx_len > (int)UART_RX_BUF_SIZE - 1) rx_len = (int)UART_RX_BUF_SIZE - 1;
uart_rx_buffer[rx_len] = '\0';
// 한 줄 만들기 (CR 무시, LF에서 끊음)
for (i = 0; i < rx_len && i < (int)sizeof(line) - 1; i++) {
char c = (char)uart_rx_buffer[i];
if (c == '\r') continue;
@ -243,103 +170,80 @@ void handle_uart_command_line(void)
}
line[idx] = '\0';
/* ============================
* X0C_
* : X0C_011:..., X0C_021:..., X0C_031:..., X0C_041:...
* () X0C_000: -> LOW
* ============================ */
if (idx >= 8 &&
(line[0]=='X' || line[0]=='x') &&
(line[1]=='0' || line[1]=='0') &&
(line[2]=='0' || line[1]=='0') &&
(line[3]=='C' || line[2]=='c') &&
line[4]=='_')
// Prefix
{
int ch = -1;
// 엄격한 포맷 검사: 'X0C_' '0' [1~4|0] '1' ':' (또는 000:)
if (line[5]=='0' && line[8]==':') {
if (line[5]=='0' && line[6]=='0' && line[7]=='0') ch = 0;
else if (line[5]=='0' && line[6]=='0' && line[7]=='1') ch = 1;
else if (line[5]=='2' && line[6]=='1') ch = 1;
else if (line[5]=='3' && line[6]=='1') ch = 2; // pin12
else if (line[5]=='4' && line[6]=='1') ch = 3; // pin13
else if (line[5]=='0' && line[6]=='0') ch = 255; // 000: -> 모두 LOW
}
uint8_t addr = 0;
uint8_t ch = 0;
int payload_pos = 0;
int r = parse_x_prefix(line, idx, &addr, &ch, &payload_pos);
if (ch == -1) {
uart_send_string("Err:X0C_code\r\n");
if (r == -1) {
uart1_send_string("Err:X_prefix\r\n");
goto clear;
}
// 모두 LOW
X0C_PORT &= (uint8_t)~(uint8_t)X0C_MASK;
__nop(); __nop(); __nop(); __nop();
// 선택된 채널만 HIGH
if (ch != 255) {
switch(ch){
case 0: X0C_PORT = (uint8_t)((X0C_PORT & (uint8_t)~(uint8_t)X0C_MASK) | X0C_CH0_MASK); break;
case 1: X0C_PORT = (uint8_t)((X0C_PORT & (uint8_t)~(uint8_t)X0C_MASK) | X0C_CH1_MASK); break;
case 2: X0C_PORT = (uint8_t)((X0C_PORT & (uint8_t)~(uint8_t)X0C_MASK) | X0C_CH2_MASK); break;
case 3: X0C_PORT = (uint8_t)((X0C_PORT & (uint8_t)~(uint8_t)X0C_MASK) | X0C_CH3_MASK); break;
}
delay_us(7000);
}
// 콜론 뒤 명령만 남기도록 버퍼를 앞으로 당김
{
int start = 8; // "X0C_0x1:" 이후 시작 인덱스
int rem = idx - start; // 남은 길이
if (rem <= 0) {
// X0C_만 있는 경우: 단순 ACK 후 종료
uart_send_string("<ACK>X0C\r\n");
if (r == 1) {
if (addr < 1 || addr > 32) { uart1_send_string("Err:addr_range\r\n"); goto clear; }
if (ch < 1 || ch > 20) { uart1_send_string("Err:ch_range\r\n"); goto clear; }
if (addr != g_fixed_addr) {
uart1_send_string("Err:addr_mismatch\r\n");
goto clear;
}
for (i = 0; i < rem; i++) line[i] = line[start + i];
line[rem] = '\0';
idx = rem;
pos = 2; // 프로토콜 재해석 위해 초기화 (OW/IR/IW/OR의 2글자 이후 위치)
ANAOUT_Select(ch);
{
int rem = idx - payload_pos;
if (rem <= 0) {
uart1_send_string("<ACK>XC\r\n");
goto clear;
}
for (i = 0; i < rem; i++) line[i] = line[payload_pos + i];
line[rem] = '\0';
idx = rem;
pos = 2;
}
}
}
// (X0C 처리 후) 최소 길이 재검사
if (idx < 7) { uart_send_string("Err:short\r\n"); goto clear; }
if (idx < 7) { uart1_send_string("Err:short\r\n"); goto clear; }
{
char h0 = (char)toupper((unsigned char)line[0]);
char h1 = (char)toupper((unsigned char)line[1]);
proto = detect_protocol(h0, h1);
}
if (proto == PROTOCOL_UNKNOWN) { uart_send_string("Err:ID\r\n"); goto clear; }
if (proto == PROTOCOL_UNKNOWN) { uart1_send_string("Err:ID\r\n"); goto clear; }
if (line[pos] == 't' || line[pos] == 'T') {
if (proto == PROTOCOL_OWIW) proto = PROTOCOL_OWIT;
else if (proto == PROTOCOL_I2CW) proto = PROTOCOL_I2CT;
pos++; // 't'
if (proto == PROTOCOL_OWIW) proto = PROTOCOL_OWIT;
else if (proto == PROTOCOL_I2CW) proto = PROTOCOL_I2CT;
pos++;
}
if (line[pos] == 'a' || line[pos] == 'A') {
if (proto == PROTOCOL_OWIW) proto = PROTOCOL_OWIA;
else if (proto == PROTOCOL_I2CW) proto = PROTOCOL_I2CA;
pos++; // 'a'
if (proto == PROTOCOL_OWIW) proto = PROTOCOL_OWIA;
else if (proto == PROTOCOL_I2CW) proto = PROTOCOL_I2CA;
pos++;
}
if (line[pos] == 'd' || line[pos] == 'D') {
if (proto == PROTOCOL_OWIW) proto = PROTOCOL_OWID;
pos++;
if (proto == PROTOCOL_OWIW) proto = PROTOCOL_OWID;
pos++;
}
if (line[pos] == 'c' || line[pos] == 'C') {
if (proto == PROTOCOL_OWIW) proto = PROTOCOL_OWIC;
else if (proto == PROTOCOL_I2CW) proto = PROTOCOL_I2CC;
if (proto == PROTOCOL_OWIW) proto = PROTOCOL_OWIC;
else if (proto == PROTOCOL_I2CW) proto = PROTOCOL_I2CC;
pos++;
}
if (line[pos] == '_' || line[pos] == ':') pos++;
if (pos + 1 >= idx) { uart_send_string("Err:id_short\r\n"); goto clear; }
if (pos + 1 >= idx) { uart1_send_string("Err:id_short\r\n"); goto clear; }
id = hex2byte(line[pos], line[pos+1]);
pos += 2;
@ -347,42 +251,42 @@ void handle_uart_command_line(void)
!(line[pos] >= '0' && line[pos] <= '9') ||
!(line[pos+1] >= '0' && line[pos+1] <= '9') ||
!(line[pos+2] >= '0' && line[pos+2] <= '9')) {
uart_send_string("Err:len_dec\r\n"); goto clear;
uart1_send_string("Err:len_dec\r\n"); goto clear;
}
byte_len = (unsigned int)(100*(line[pos]-'0') + 10*(line[pos+1]-'0') + (line[pos+2]-'0'));
pos += 3;
if (byte_len > CMD_MAX) { uart_send_string("Err:len_range\r\n"); goto clear; }
if (byte_len > CMD_MAX) { uart1_send_string("Err:len_range\r\n"); goto clear; }
if (proto == PROTOCOL_I2CA || proto == PROTOCOL_OWIA) {
if (byte_len != 0 && byte_len != 3) {
uart_send_string("Err:len_a_mode\r\n"); goto clear;
uart1_send_string("Err:len_a_mode\r\n"); goto clear;
}
if (byte_len == 0) {
if (pos != idx) { uart_send_string("Err:read_no_payload\r\n"); goto clear; }
if (pos != idx) { uart1_send_string("Err:read_no_payload\r\n"); goto clear; }
} else {
if ((int)(pos + (int)byte_len*2) > idx) { uart_send_string("Err:len_mismatch\r\n"); goto clear; }
if ((int)(pos + (int)byte_len*2) > idx) { uart1_send_string("Err:len_mismatch\r\n"); goto clear; }
for (k = 0; k < byte_len; k++) {
cmd[k] = hex2byte(line[pos + 2*k], line[pos + 2*k + 1]);
}
pos += byte_len*2;
if (pos != idx) { uart_send_string("Err:len_trail\r\n"); goto clear; }
if (pos != idx) { uart1_send_string("Err:len_trail\r\n"); goto clear; }
}
}
}
else if (proto == PROTOCOL_OWIT || proto == PROTOCOL_I2CT ||
proto == PROTOCOL_OWIW || proto == PROTOCOL_I2CW)
proto == PROTOCOL_OWIW || proto == PROTOCOL_I2CW)
{
if (byte_len == 0) { uart_send_string("Err:payload0\r\n"); goto clear; }
if ((int)(pos + (int)byte_len*2) > idx) { uart_send_string("Err:len_mismatch\r\n"); goto clear; }
if (byte_len == 0) { uart1_send_string("Err:payload0\r\n"); goto clear; }
if ((int)(pos + (int)byte_len*2) > idx) { uart1_send_string("Err:len_mismatch\r\n"); goto clear; }
for (k = 0; k < byte_len; k++) {
cmd[k] = hex2byte(line[pos + 2*k], line[pos + 2*k + 1]);
}
pos += byte_len*2;
if (pos != idx) { uart_send_string("Err:len_trail\r\n"); goto clear; }
if (pos != idx) { uart1_send_string("Err:len_trail\r\n"); goto clear; }
}
else if (proto == PROTOCOL_OWIR || proto == PROTOCOL_I2CR)
else if (proto == PROTOCOL_OWIR || proto == PROTOCOL_I2CR)
{
if (byte_len == 0) { uart_send_string("Err:read_len_nonzero\r\n"); goto clear; }
if (pos != idx) { uart_send_string("Err:read_no_payload\r\n"); goto clear; }
if (byte_len == 0) { uart1_send_string("Err:read_len_nonzero\r\n"); goto clear; }
if (pos != idx) { uart1_send_string("Err:read_no_payload\r\n"); goto clear; }
}
process_cmd(proto, id, cmd, byte_len);
@ -391,11 +295,17 @@ void handle_uart_command_line(void)
idx = 0;
uart_rx_index = 0;
uart_rx_length = 0;
R_UART0_Receive((uint8_t *)&uart_rx_buffer[uart_rx_index], 1);
R_UART1_Receive((uint8_t *)&uart_rx_buffer[uart_rx_index], 1);
}
}
}
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
void R_MAIN_UserInit(void);
/***********************************************************************************************************************
@ -408,12 +318,20 @@ void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
R_UART0_Create();
R_IICA0_Create();
R_UART0_Start();
R_UART0_Receive(&uart_rx_buffer[uart_rx_index], 1);
R_UART0_Create(); // UART0
R_UART1_Create(); // UART1
R_IICA0_Create(); // I2C
R_UART0_Start(); // RS485
R_UART1_Start(); // PC
R_UART1_Receive((uint8_t *)&uart_rx_buffer[uart_rx_index], 1);
handle_uart_command_line();
delay(100000);
while (1U)
{
;
@ -431,9 +349,17 @@ void R_MAIN_UserInit(void)
{
/* Start user code. Do not edit comment generated here */
EI();
R_PORT_Create();
rs485_init();
R_ADC_Create();
R_ADC_Set_OperationOn();
x0c_init();
DipSwitch_Init();
g_fixed_addr = DipSwitch_ReadAddr_1to32();
ANAOUT_Init();
/* End user code. Do not edit comment generated here */
}

7
r_systeminit.c

@ -23,7 +23,7 @@
* Device(s) : R5F10PPJ
* Tool-Chain : CCRL
* Description : This file implements system initializing function.
* Creation Date: 2026-01-12
* Creation Date: 2026-01-13
***********************************************************************************************************************/
/***********************************************************************************************************************
@ -31,7 +31,9 @@ Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_cgc.h"
#include "r_cg_port.h"
#include "r_cg_serial.h"
#include "r_cg_adc.h"
#include "r_cg_wdt.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
@ -69,8 +71,11 @@ void R_Systeminit(void)
PIOR8 = 0x00U;
R_CGC_Get_ResetSource();
R_CGC_Create();
R_PORT_Create();
R_SAU0_Create();
R_SAU1_Create();
R_IICA0_Create();
R_ADC_Create();
R_WDT_Create();
/* Set invalid memory access detection control */

182
uart.c

@ -0,0 +1,182 @@
#include "uart.h"
#include "delay.h"
#include "r_cg_adc.h"
#include "r_cg_port.h"
#define RS485_EN_PORT P4
#define RS485_EN_PM PM4
#define RS485_EN_MASK (0x20U) // P4.5
float g_adc_bytes[ADC_NUM_CH] = {0.0f};
uint8_t g_adc_len = 0;
void rs485_set_tx(uint8_t on)
{
if (on) RS485_EN_PORT |= RS485_EN_MASK; // EN=1 (TX)
else RS485_EN_PORT &= (uint8_t)~RS485_EN_MASK; // EN=0 (RX)
}
void rs485_init(void)
{
RS485_EN_PM &= (uint8_t)~RS485_EN_MASK; // 출력
rs485_set_tx(0); // 기본 RX 모드
}
/**
* : uart_send_string
* : null UART0로
*
* :
* - str : (C , '\0' )
*
* : (void)
*
* :
* 1)
* - '\0' len
*
* 2) UART
* - R_UART0_Send()
* - (uint8_t *)
*
* :
* - null ('\0')
* - UART0
*/
// UART0(RS485)
void uart_send_string(const char *str)
{
uint16_t len = 0;
while (str[len] != '\0') len++;
rs485_set_tx(1);
R_UART0_Send((uint8_t *)str, len);
}
// UART1(PC)
void uart1_send_string(const char *str)
{
uint16_t len = 0;
while (str[len] != '\0') len++;
R_UART1_Send((uint8_t *)str, len);
}
/**
* : uart_send_hex
* : 8 (uint8_t) 16 UART0로
*
* :
* - val : 8
*
* : (void)
*
* :
* 1) / 4
* - high = val >> 4, 4
* - low = val & 0x0F, 4
*
* 2) 16
* - 0~9 '0'~'9'
* - 10~15 'A'~'F'
* - hex[0] = 4
* - hex[1] = 4
*
* 3) UART
* - R_UART0_Send() 2
*
* 4)
* - delay(10000)
*
* :
* - 1 2 16
* - : val = 0xAF "AF"
*/
void uart_send_hex(uint8_t val)
{
uint8_t hex[2];
uint8_t high = (val >> 4) & 0x0F;
uint8_t low = val & 0x0F;
hex[0] = (high < 10) ? ('0' + high) : ('A' + (high - 10));
hex[1] = (low < 10) ? ('0' + low) : ('A' + (low - 10));
rs485_set_tx(1);
R_UART0_Send(hex, 2);
delay(10000);
}
void uart1_send_hex(uint8_t val)
{
uint8_t hex[2];
uint8_t high = (val >> 4) & 0x0F;
uint8_t low = val & 0x0F;
hex[0] = (high < 10) ? ('0' + high) : ('A' + (high - 10));
hex[1] = (low < 10) ? ('0' + low ) : ('A' + (low - 10));
R_UART1_Send(hex, 2);
delay(10000);
}
/**
* : ADC_ReadAndSend_UART
* : ADC
*
* :
* 1) ADC
* - ADC_NUM_CH
* - : {0x02, 0x03, 0x04, 0x05}
*
* 2)
* for (i = 0; i < ADC_NUM_CH; i++)
* a) ADS
* b) R_ADC_Start()
* c) (ADIF == 1 )
* d) ADIF
* e) : R_ADC_Get_Result(&adc_value)
* f) ADC : R_ADC_Stop()
*
* 3) ADC
* - voltage = (adc_value / ADC_RESOLUTION) * VREF
* - : 12bit ADC, VREF = 5V이면 0~4095 0~5V
*
* 4)
* - g_adc_bytes[i] = voltage
* - g_adc_len
*
* :
* - g_adc_bytes[]:
* - g_adc_len:
*/
void ADC_ReadAndSend_UART(void)
{
static const uint8_t ADC_CHANNELS[ADC_NUM_CH] = { 0x02,0x03,0x04,0x05};
uint16_t adc_value;
float voltage;
int i;
g_adc_len = 0;
for (i = 0; i < ADC_NUM_CH; i++) {
ADS = ADC_CHANNELS[i]; // 채널 선택
R_ADC_Start(); // 변환 시작
while (ADIF == 0U); // 변환 완료 대기
ADIF = 0U;
R_ADC_Get_Result(&adc_value);
R_ADC_Stop();
/* V 계산 */
voltage = (adc_value / ADC_RESOLUTION) * VREF;
g_adc_bytes[i] = voltage;
g_adc_len++;
}
}

37
uart.h

@ -0,0 +1,37 @@
#include "r_cg_macrodriver.h"
#include "r_cg_serial.h"
#include "r_cg_adc.h"
#define ADC_RESOLUTION 1023.0f // 10-bit ADC
#define VREF 5.06f // V
#define ADC_NUM_CH 4
#define RAM_BYTES 13
#define UART_RX_BUF_SIZE 96
extern float g_adc_bytes[ADC_NUM_CH];
extern uint8_t g_adc_len;
extern volatile uint8_t uart_rx_done;
extern volatile uint8_t uart_rx_index;
extern volatile uint8_t uart_rx_buffer[UART_RX_BUF_SIZE];
extern volatile uint16_t uart_rx_length;
void uart_send_string(const char *str); // UART0(RS485)
void uart_send_hex(uint8_t val); // UART0(RS485)
void uart1_send_string(const char *str); // UART1(PC)
void uart1_send_hex(uint8_t val); // UART1(PC)
//void UART0_ReceiveHandler(void);
void ADC_ReadAndSend_UART(void);
void cmd_enter_command_mode(const unsigned char *d, unsigned int len);
void cmd_unknown(const unsigned char *d, unsigned int len);
// RS485 EN(P45)
void rs485_init(void);
void rs485_set_tx(uint8_t on);
Loading…
Cancel
Save