L
ON
W
ORKS
I
NTERFACE
M
ODULE
O
PEN
N
ET
C
ONTROLLER
L
ON
W
ORKS
I
NTERFACE
M
ODULE
U
SER
’
S
M
ANUAL
21
Writing Receive Data to Data Registers in the L
ON
W
ORKS
Interface Module
The following diagram shows a typical example of writing receive data to the data registers in the L
ON
W
ORKS
interface
module.
Application Program Example for Data Write
The following program is an example to write receive data to data register C000h of the L
ON
W
ORKS
interface module
when an 8-bit input network variable (nv_i8) is updated. When you modify or create an application program, make sure
that the application program includes the following codes in italics.
1.
/* Input Network Variables */
2.
network input unsigned char nv_i8;
3.
/* define */
4.
#define GA_BCTL 0xC01A
5.
#define BCTL_NWR_REQ 0x04
6.
#define GA_FCDR_RX 0xC000
7.
8.
when(nv_update_occurs(nv_i8)){ /* Acknowledge input network variable update */
9.
unsigned char *pGA;
10. unsigned char dat;
11. while(TRUE){
12. pGA = (unsigned char *)GA_BCTL; /* Preparation for data write */
13. *pGA |= BCTL_NWR_REQ;
14. dat = *pGA;
15. if (dat & BCTL_NWR_REQ){ /* Preparation for data write complete */
16. pGA = (unsigned char *)GA_FCDR_RX;
17. pGA = nv_i8; /* Write input NV data to data register C000h */
18. pGA = (unsigned char *)GA_BCTL;
19. pGA &= ~BCTL_NWR_REQ; /* End data write */
20. break;
21. }
22. }
23. }
NO
YES
Is preparation for data
write complete?
Preparation for data write
Write data
End data write