英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流

 找回密码
 立即注册
搜索
电子烟方案单片机单片机开发深圳单片机开发
单片机方案国产单片机8位单片机电子烟方案开发
查看: 3464|回复: 2
打印 上一主题 下一主题

如果是接收串口发送过来的数据,一定也要用串口吗

[复制链接]
跳转到指定楼层
1#
发表于 2009-3-16 14:35:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
还是可以用普通I/O口模拟串口
2#
 楼主| 发表于 2009-3-16 14:35:31 | 只看该作者
用普通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()
{
   int8  x = 34;

   while(1)
   {
      putc( fgetc(GPS) );

      printf("x= %d ", x);

      fprintf(ICP, "x= %d ", x);

      delay_ms(1000);
   }
}
回复 支持 反对

使用道具 举报

3#
 楼主| 发表于 2009-3-16 14:36:10 | 只看该作者
用普通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 bit  address)

SDA=pin
Specifies the SDA pin

ADDRESS=nn
Specifies the slave mode  address

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 下一条

小黑屋|公司首页|Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 ( 粤ICP备09008620号 )

GMT+8, 2024-4-28 07:28 , Processed in 0.051991 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表