如果是接收串口发送过来的数据,一定也要用串口吗
还是可以用普通I/O口模拟串口 用普通I/O口模拟串口,CCS 讓你一分鐘搞定#include <16F877.H> // <18F452.H> // device header file from CCS-C
#use delay(clock=20000000) // 20 MHz crystal oscillator
#use rs232(baud= 4800, xmit=PIN_B6, rcv=PIN_B7, stream=ICP)
#use rs232(baud= 9600, xmit=PIN_B1, rcv=PIN_B2, stream=GPS)
#use rs232(baud= 1200, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
int8x = 34;
while(1)
{
putc( fgetc(GPS) );
printf("x= %d ", x);
fprintf(ICP, "x= %d ", x);
delay_ms(1000);
}
} 用普通I/O口模拟 I2C , CCS 讓你半分鐘搞定
#USE I2C
Syntax:
#use i2c (options)
Elements:
Options are separated by commas and may be:
MASTER
Set the master mode
SLAVE
Set the slave mode
SCL=pin
Specifies the SCL pin (pin is a bitaddress)
SDA=pin
Specifies the SDA pin
ADDRESS=nn
Specifies the slave modeaddress
FAST
Use the fast I2C specification
SLOW
Use the slow I2C specification
RESTART_WDT
Restart the WDT while waiting in I2C_READ
FORCE_HW
Use hardware I2C functions.
Purpose:
The I2C library contains functions to implement an I2C bus. The #USE I2C remains in effect for the I2C_START, I2C_STOP, I2C_READ, I2C_WRITE and I2C_POLL functions until another USE I2C is encountered.Software functions are generated unless the FORCE_HW is specified.The SLAVE mode should only be used with the built-in SSP.
Examples:
#use I2C(master, sda=PIN_B0, scl=PIN_B1)
#use I2C(slave,sda=PIN_C4,scl=PIN_C3
address=0xa0,FORCE_HW)
Example Files:
ex_extee.c with 2464.c
Also See:
i2c_read(), i2c_write()
页:
[1]