📄 main.c
字号:
// ---------------------------------------------------------------------------
// DISCLAIMER:
// We (RENESAS TECHNOLOGY EUROPE) do not warrant that the Software is
// free from claims by a third party of copyright, patent, trademark,
// trade secret or any other intellectual property infringement.
//
// Under no circumstances are we liable for any of the following:
//
// 1. third-party claims against you for losses or damages;
// 2. loss of, or damage to, your records or data; or
// 3. economic consequential damages (including lost profits or
// savings) or incidental damages, even if we are informed of
// their possibility.
//
// We do not warrant uninterrupted or error free operation of the
// Software. We have no obligation to provide service, defect
// correction, or any maintenance for the Software. We have no
// obligation to supply any Software updates or enhancements to you
// even if such are or later become available.
//
// IF YOU DOWNLOAD OR USE THIS SOFTWARE YOU AGREE TO THESE TERMS.
//
// THERE ARE NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE.
// ---------------------------------------------------------------------------
// Copyright (c) 2005 RENESAS TECHNOLOGY EUROPE All rights reserved.
// ---------------------------------------------------------------------------
// S O U R C E F O R M A T
// ---------------------------------------------------------------------------
// tab width 4 (tab at 4 8 12 ...)
// ---------------------------------------------------------------------------
// Project Name: I2C
// File : Test_I2c.c
// Description : Test program to confirm that I睠 bus is running properly
// ---------------------------------------------------------------------------
// Supported : IAR M16C C/EC++ Compiler V2.12A/W32
// Compiler
// ---------------------------------------------------------------------------
// R E V I S I O N
// ---------------------------------------------------------------------------
// Supported Compiler : IAR
// ---------------------------------------------------------------------------
// R E V I S I O N H I S T O R Y
// ---------------------------------------------------------------------------
// Date Ver Author Description
// ---------------------------------------------------------------------------
// 25/01/2005 1.0 TMA Creation
// ---------------------------------------------------------------------------
// R E M A R K S
// Tested on device : M16C/26
// ---------------------------------------------------------------------------
#include "i2c.h"
#include "uart.h"
#include "hardware.h"
unsigned char data[8];
const unsigned char text[2];
unsigned char data_check[sizeof text];
unsigned char data_write[sizeof text];
unsigned char i;
unsigned long l, nb_errors, nb_access;
// ---------------------------------------------------------------------------
void SI03_INT4_ISR(void)
{
char data = 0x00;
//disable_interrupt();
//_printf("abcdef");
I2C_MasterWrite(0xA2, &data, 1);
while (I2C_getStatus().bit.busy==TRUE) {}
I2C_MasterRead(0xA3, data_check, 2);
while (I2C_getStatus().bit.busy==TRUE) {}
_printf("I2C Read: %i, %i", data_check[0], data_check[1]);
//enable_interrupt();
}
/**********************
* Potentialy Called by cstartup *
**********************/
unsigned char low_level_init(void) {
// Configure the system clock
// Xin / Xout Oscillation at 30MHz
//PD8.BYTE = PD8.BYTE & ~(PD8.BIT.PD8_6|PD8.BIT.PD8_7); /*Bit 6 and 7 as input on port 8 => Xcin-Xcout*/
//P8.BYTE = 0; // debug only !
//PD8.BYTE = 0x07; // debug only !
// P72 = WP , P73&P74&P75 = address
// P76&P77 = trig signals
P7.BYTE = 0x10; // Enable write to EEPROM with address 010 (2)
#ifdef M16C62P
#ifdef EVA_3DK62P
PRCR |= 0x01; // Enable write to system clock
CM1 = 0x20; //Setting System clock control register 1
CM0 = 0x18; //Setting System clock control register 0
PLC0 = 0x12; // for M16C/62P using 6MHZ Xin
PLC0 = 0x92; // for M16C/62P using 6MHZ Xin (remove this line without PLL)
PRCR &= ~0x01; // Inhibite write to system clock
#endif
#ifdef UART0
IFSR2A |= 0x40;
#endif
#ifdef UART1
IFSR2A |= 0x80;
#endif
#endif
#ifdef M16C6N4
#ifdef UART0
IFSR0 |= 0x40;
#endif
#ifdef UART1
IFSR0 |= 0x80;
#endif
PRCR = 4; // Enable access to PD7
#endif
PD7.BYTE = 0xFC;
return 1; /* Force cstartup to initialise RAM etc. */
}
int main(void)
{
char data = 0x08;
low_level_init();
//for(i=0;i!=sizeof(text);i++)
//data_write[i] = text[i];
/* uart1 initiation */
PD6.BIT.PD6_6 = INPUT; // set port P66 to INPUT (RXD1)
PD6.BIT.PD6_7 = OUTPUT; // set port P67 to OUTPUT (TXD1)
U1BRG = ((MAIN_CLOCK / (16.0 * 9600)) - 1.0); // set UART1 bit rate generator
U1MR.BYTE = 0x05; // 8 data bits
U1C0.BYTE = 0x10; // select f1, CTS/RTS function disabled
U1C1.BIT.TE = 1; // enable transmit
U1C1.BIT.RE = 1; // enable receive
S1RIC.BYTE = 0x04; // set UART1 receive interrupt priority level 4
/* interrupt 4 initiation */
IFSR.BIT.IFSR6 = 1; // enable interrupt4
IFSR.BIT.IFSR4 = 0; // One edge interrupt
PD1.BIT.PD1_6 = INPUT; // set port P16 (=INT4) as INPUT port
INT4IC.BYTE = 0x03; // enable interrupt4, level 3, falling edge
nb_errors = 0;
nb_access = 0;
I2C_init();
enable_interrupt();
_printf("Initialisation of MULLE done!\n\n");
I2C_MasterWrite(0xA2, &data, 1);
while (I2C_getStatus().bit.busy==TRUE) {}
I2C_MasterRead(0xA3, data_check, 2);
while (I2C_getStatus().bit.busy==TRUE) {}
_printf("I2C Read: %i, %i\n", data_check[0], data_check[1]);
while (TRUE) {
//i = 0;
/*while (i != sizeof(text)) {
data[0] = i; // Memory address to be used
data[1] = data_write[i]; // Data to store
I2C_MasterWrite(0xA2, data, 2);
while (I2C_getStatus().bit.busy==TRUE) {}
while (I2C_getStatus().bit.nack == TRUE) {
I2C_MasterWrite(0xA3, data, 1);
while(I2C_getStatus().bit.busy==TRUE) {}
}
data_check[i]=0;
i++;*/
// Set address to beof buffer
/*data[0] = 0; // Memory address to be used
I2C_MasterWrite(0x52, data, 1); // dummy write to fix address counter inside eeprom
while(I2C_getStatus().bit.busy==TRUE){}
I2C_MasterRead(0x52,data_check,sizeof(text));
while(I2C_getStatus().bit.busy==TRUE){}
for(i=0;i!=sizeof(text);i++)
{
if(data_check[i] != data_write[i]) nb_errors++;
}
nb_access ++;
}*/
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -