EDN首页   博客首页

1

关于投票
iccavr用户手册(中文)
http://space.ednchina.com/upload/2008/10/20/370fcf86-59d6-46f9-a7e5-e0128d29e60d.rariccavr用户手册
系统分类: 单片机
用户分类: 单片机
标签: ICCAVR AVR 用户手册
来源: 转贴
发表评论 阅读全文(164) | 回复(0)

3

关于投票
STM32 protel 封装(不断更新中)

点击下载STM32 Protel 封装

只画了三个封装(LQFP48,LQFP64,LQFP100)

系统分类: 单片机
用户分类: 单片机
标签: STM32 封装
来源: 原创
发表评论 阅读全文(532) | 回复(4)

3

关于投票
AVR方面比较好的国外网站(不断更新中)
http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial#Flash_in_der_Anwendung_schreiben
avr gcc的原理方面的东西, 好好长的外文, 更变态的是居然不是英文。
用AVR单片机实现TCP/IP协议,这个网站上有很多这方面的资料
一个老外的个人网站。
Mini DDS。
AVRX作者的网站
上面又很多avr做的东西。
大名鼎鼎。
看名字就知道了。

这个去的少。



http://www.avr-asm-tutorial.net/avr_en/index.html

不错。
不错。
 
 
国内的推荐
http://www.ouravr.com
系统分类: 单片机
用户分类: 单片机
标签: AVR
来源: 整理
发表评论 阅读全文(406) | 回复(2)

1

关于投票
AVR 单片机GCC 程序设计

rar学习AVR单片机很好的资料,特别适用初学者

系统分类: 单片机
用户分类: 单片机
标签: 无标签
来源: 转贴
发表评论 阅读全文(136) | 回复(0)

4

关于投票
led数码管编码软件

一个很实用的小工具!!!(led数码管编码生成软件)

系统分类: 单片机
用户分类: 单片机
标签: 数码管 编码 软件 LED
来源: 整理
发表评论 阅读全文(482) | 回复(0)

3

关于投票
怎样用最少的IO口驱动最多的发光二极管????

点击开大图

如上图所示当IO1为输出高电平,IO2输出低电平,其它IO口为高阻态,D4导通,而D2D12D10D7D6因串连电阻5个,加起来电阻值有2.5K 加上自身的导通电阻,流经它们的电流很小,因而不会发光。其它LED用同样的方法可以依次扫描导通。

以上是5IO口以上的驱动方法,而小于5IO口就不能用以上方法连起来,用下图

点击开大图

系统分类: 单片机
用户分类: 单片机
标签: 单片机 I/O LED 发光二极管
来源: 原创
发表评论 阅读全文(531) | 回复(0)

2

关于投票
一个很不错的I2C读写程序(基于KeilC51),运行稳定,可靠性高

点击下载

#include "C8051F310.H"
#include "common.h"
#include "i2c.h"

/* Ports */
sbit SCL  = P0 ^ 7;
sbit SDA  = P0 ^ 6;
sbit CHECK  = P1 ^ 0;

/* ------------ DEFINES --------------- */
/* I2c read/write flags */
#define I2C_WRITE_FLAG 0x00 /* bit 0 of slave-addres byte */
#define I2C_READ_FLAG 0x01

/* bus logic levels */
#define LO  0
#define HI 1

/* Delay constants */
#define _5US 8

/* Retry times on NACK */
#define NACK_RETRY_MAX 5

/* ------------ LOCAL DATA ------------ */
xdata UINT8 I2cStatus;
xdata UINT8 RxBit;
xdata UINT8 RxByte;

/* ---------- MODULE FUNCTIONS  ------- */
void Delay ( UINT8 Time );
UINT8 SetScl( UINT8 State );
UINT8 SetSda( UINT8 State );
void FloatSda( void );
UINT8 I2cStart();
UINT8 I2cStop();
UINT8 I2cTxBit( UINT8 BitVal );
UINT8 I2cRxBit( void );
UINT8 I2cTxByte( UINT8 TxData);
UINT8 I2cRxByte( UINT8 AckState );


/*---------------- Function Header -------------------------------------------

 FUNCTION InitI2c
 PURPOSE  Initialises I2c driver
 INPUT  None
 OUTPUT  I2c status byte indicating the idle-state of the bus
 
----------------------------------------------------------------------------*/
UINT8 InitI2c ( void )
{

 /* configure C8051F310 ports for I2C operation:
  SDA is connected to Port0, bit6
  SCL is connected to Port0, bit7
  both pins function in open-drain mode
 */
 P0SKIP = 0xc0;
 P0MDOUT &= ~0x30; /* set SDA and SCL = open-drain */
 
 I2cStatus = 0;  /* initialise driver status */
 
 /* set initial idle state for bus (SDA and SCL = 1) */
 return ( SetSda( HI ) || SetScl( HI ) );

}

/*---------------- Function Header -------------------------------------------

 FUNCTION Delay
 PURPOSE  Programme delay in the microsecond range -
    Called to meet I2C bus timing requirements

----------------------------------------------------------------------------*/
void Delay ( UINT8 Time )
{
 UINT8 i;

 EA = 0;      /* interrupts disabled during delay */
 for (i = 0; i < Time; i++);
 EA = 1;
}

/*---------------- Function Header -------------------------------------------

 FUNCTION SetScl
 PURPOSE  Sets I2C SCL line to the required level. Because the bus is a
    wire-OR configuration, it may take some time to establish a
    logic '1' due to slow risetime, clock stretching etc.
    An arbitrary timeout of 250us is allowed.
 INPUT  Required bus state
 OUTPUT  Flag indicating result: 1 = OK, 0 = bus line stuck.
 MODIFIES I2cStatus
    
----------------------------------------------------------------------------*/
UINT8 SetScl( UINT8 State )
{
// UINT16 Timeout = 450; /* approx 250us */
 UINT16 Timeout = 10000; /* approx 250us */

 SCL = State;
 while ( (SCL != State) && --Timeout);

 if ( Timeout )
  return true;
 else
 {
  I2cStatus |= I2C_ERROR_SCL_STUCK;
  return false;
 }
}

/*---------------- Function Header -------------------------------------------

 FUNCTION SetSda
 PURPOSE  Sets I2C SDA line to the required level. Because the bus is a
    wire-OR configuration, it may take some time to establish a
    logic '1' due to slow risetime, clock stretching etc.
    An arbitrary timeout of 250us is allowed.
 INPUT  Required bus state
 OUTPUT  Flag indicating result: 1 = OK, 0 = bus line stuck.
 MODIFIES I2cStatus
    
----------------------------------------------------------------------------*/
UINT8 SetSda( UINT8 State )
{
// UINT16 Timeout = 450; /* approx 250us */
 UINT16 Timeout = 10000; /* approx 250us */

 SDA = State;
 while ( (SDA != State) && --Timeout);

 if ( Timeout )
  return true;
 else
 {
  I2cStatus |= I2C_ERROR_SDA_STUCK;
  return false;
 }
}

/*---------------- Function Header -------------------------------------------

 FUNCTION FloatSda
 PURPOSE  Sets I2C SDA line to 'input mode'.
    Note: this function does not check the line is high because
    a slave may be legitimately driving SDA low.
    
----------------------------------------------------------------------------*/
void FloatSda( void )
{
 SDA = HI;
}

/*---------------- Function Header -------------------------------------------

 FUNCTION I2cStart
 PURPOSE  Applies an appropriately timed START condition to the I2c bus.
 OUTPUT  Flag indicating result: 1 = OK, 0 = bus line stuck.
 MODIFIES I2cStatus
    
----------------------------------------------------------------------------*/
UINT8 I2cStart()
{
 if ( !SDA )  /* ensure SDA is high */
 {
  if ( !SetSda(HI) )
   return false;
 }

 if ( !SCL )  /* ensure SCL is high */
 {
  if ( !SetScl(HI) )
   return false;
 }

 Delay( _5US );    /* Philips tSU:STA > 4.7us */

 SetSda(LO);
 Delay( _5US );    /* Philips tHD:SDA > 4us */
 
 return ( SetScl(LO) );
}

/*---------------- Function Header -------------------------------------------

 FUNCTION I2cStop
 PURPOSE  Applies an appropriately timed STOP condition to the I2c bus.
 OUTPUT  Flag indicating result: 1 = OK, 0 = bus line stuck.
 MODIFIES I2cStatus
    
----------------------------------------------------------------------------*/
UINT8 I2cStop()
{
 SetSda(LO); /* ensure SDA is low */

 if ( !SetScl(HI) )
  return false;
 Delay( _5US );    /* Philips tSU:STO > 4us */
 
 return ( SetSda(HI) );
}

/*---------------- Function Header -------------------------------------------

 FUNCTION I2cTxBit
 PURPOSE  Drives the specified data bit to the I2c bus.
 OUTPUT  Flag indicating result: 1 = OK, 0 = bus line stuck.
 MODIFIES I2cStatus
    
----------------------------------------------------------------------------*/
UINT8 I2cTxBit( UINT8 BitVal )
{
 if ( !SetSda(BitVal) )
  return false;
 Delay( _5US );    /* Philips tLOW > 4.7us */

 if ( !SetScl(HI) )
  return false;
 Delay( _5US );    /* Philips tHIGH > 4us */
 
 return ( SetScl(LO) );
}

/*---------------- Function Header -------------------------------------------

 FUNCTION I2cRxBit
 PURPOSE  Receives a data bit from the I2c bus.
 OUTPUT  Flag indicating result: 1 = OK, 0 = bus line stuck.
    Data bit is saved to RxBit
 MODIFIES I2cStatus
    
----------------------------------------------------------------------------*/
UINT8 I2cRxBit( void )
{
 FloatSda(); /* float SDA - can't check state as slave maybe driving SDA */
 Delay( _5US );    /* Philips tLOW > 4.7us */

 if ( !SetScl(HI) )
  return false;
 Delay( _5US );    /* Philips tHIGH > 4us */
 RxBit = SDA;
 return ( SetScl(LO) );
}

/*---------------- Function Header -------------------------------------------

 FUNCTION I2cTxByte
 PURPOSE  Sequences transmission of a data byte to the I2c bus.
 OUTPUT  Flag indicating result: 1 = slave acknowledged, 0 = no ack/fail.
    Data bit is saved to RxBit
 MODIFIES I2cStatus: State of ACK bit and error flags
    
----------------------------------------------------------------------------*/
UINT8 I2cTxByte( UINT8 TxData)
{
 UINT8 i;
 UINT8 t = TxData;

 for (i= 0;i < 8;i++)
 {
  if ( !I2cTxBit( (t & 0x80) ? 1 : 0 ) )
   return false;
  t <<= 1;
 }

 if ( I2cRxBit() )
 {
  if (RxBit)
   I2cStatus |= I2C_ERROR_NO_ACK;
  return ( !RxBit ); /* returns '1' if ACK recieved */
 }
 else
  return false;

}

/*---------------- Function Header -------------------------------------------

 FUNCTION I2cTxByte
 PURPOSE  Sequences reception of a data byte from the I2c bus.
 INPUT  Flag indicating state of ACK bit to be sent to the slave
 OUTPUT  Flag indicating result: 1 = OK, 0 = fail.
    Data byte is saved to RxByte
 MODIFIES I2cStatus: State of error flags
    
----------------------------------------------------------------------------*/
UINT8 I2cRxByte( UINT8 AckState )
{
 UINT8 i;
 UINT8 r = 0;

 for (i= 0;i < 8;i++)
 {
  if ( !I2cRxBit() )
   return false;
  r <<= 1;
  r |= RxBit;
 }

 RxByte = r;

 return ( I2cTxBit ( AckState ) );

}

/*---------------- Function Header -------------------------------------------

 FUNCTION I2cWrite
 PURPOSE  Sequences a write-cycle to a slave device on the I2c bus.
    send START
    send slave-adddress + write flag (check ACK)
    send write pointer (check ACK)
    read data bytes (with NACK at last byte) (check all ACKs)
 INPUT  I2cAddress:    specifies slave device 7-bit address
    DeviceAddress: specifies address pointer within the device
    Data:          Pointer to write-data (byte) array
    ByteCount:     specifies number of bytes to write
 OUTPUT  I2cStatus byte indicating result of I2c cycle.
 MODIFIES I2cStatus:     all flags
    
----------------------------------------------------------------------------*/
UINT8 I2cWrite( UINT8 I2cAddress, UINT8 DeviceAddress, UINT8 *Data, UINT8 ByteCount)
{
 UINT8 i;
 UINT8 *WriteDataPtr;
 
CHECK = 1;
 i = 0;
 
 do { /* attempt to address device up to NACK_RETRY_MAX times */
 
  I2cStatus = 0;

  if ( I2cStart() )
  {
   if ( !I2cTxByte( (I2cAddress * 2) + I2C_WRITE_FLAG ) )
    I2cStop();
  }
 } while ( (I2cStatus != 0) && (++i < NACK_RETRY_MAX) );
CHECK = 0;

 if ( i >= NACK_RETRY_MAX )
  return I2cStatus;
 

 if ( !I2cTxByte( DeviceAddress ) )
 {
  I2cStop();
  return I2cStatus;
 }

 WriteDataPtr = Data;
 for ( i = 0; i < ByteCount; i++)
 {
  if ( !I2cTxByte( *WriteDataPtr++ ) )
  {
   I2cStop();
   return I2cStatus;
  }
 }

 I2cStop();
 return I2cStatus;
}

/*---------------- Function Header -------------------------------------------

 FUNCTION I2cRead
 PURPOSE  Sequences a read-cycle to a slave device on the I2c bus:
    send START
    send slave-adddress + write flag (check ACK)
    send read pointer (check ACK)
    send re-START
    send slave-adddress + read flag (check ACK)
    read data bytes (with NACK at last byte)
 INPUT  I2cAddress:    specifies slave device 7-bit address
    DeviceAddress: specifies address pointer within the device
    Data:          Pointer to return-data (byte) array
    ByteCount:     specifies number of bytes to read
 OUTPUT  I2cStatus byte indicating result of I2c cycle.
 MODIFIES I2cStatus:     all flags
    
----------------------------------------------------------------------------*/
UINT8 I2cRead( UINT8 I2cAddress, UINT8 DeviceAddress, UINT8 *Data, UINT8 ByteCount)
{
 UINT8 i;
 UINT8 *ReadDataPtr;
 
 i = 0;
 do { /* attempt to address device up to NACK_RETRY_MAX times */
 
  I2cStatus = 0;

  if ( I2cStart() )
  {
   if ( !I2cTxByte( (I2cAddress * 2) + I2C_WRITE_FLAG ) )
    I2cStop();
  }
 } while ( (I2cStatus != 0) && (++i < NACK_RETRY_MAX) );

 if ( i >= NACK_RETRY_MAX )
  return I2cStatus;


 if ( !I2cTxByte( DeviceAddress ) )
 {
  I2cStop();
  return I2cStatus;
 }

 i = 0;
 do { /* attempt to address device up to NACK_RETRY_MAX times */
 
  I2cStatus = 0;

  if ( I2cStart() )
  {
   if ( !I2cTxByte( (I2cAddress * 2) + I2C_READ_FLAG ) )
    I2cStop();
  }
 } while ( (I2cStatus != 0) && (++i < NACK_RETRY_MAX) );

 if ( i >= NACK_RETRY_MAX )
  return I2cStatus;


 ReadDataPtr = Data;
 for ( i = 0; i < ByteCount; i++)
 {
  if ( I2cRxByte( (i == (ByteCount - 1) ? 1 : 0 ) ) )
    *ReadDataPtr++ = RxByte;
  else
  {
   I2cStop();
   return I2cStatus;
  }
 }

 I2cStop();
 return I2cStatus;
}

系统分类: 单片机
用户分类: 单片机
标签: I2C eeprom KeilC51 读写程序
来源: 转贴
发表评论 阅读全文(425) | 回复(0)

4

关于投票
AVR单片机4个I/O口可以设计出12个按键!!

点击看大图

AVR单片机的I/O口有4个状态(输出0,输出1,内部电阻拉高(输入),高阻态)。如上图所示当IO1为输入(内部电阻拉高)、IO2输出低电平、其它IO口为高阻态时,若单片机检测到IO1被拉低,根据二极管单向导通原理,可以判断S11被按下。同理,当IO2为输入(内部电阻拉高),IO1输出低电平,其它IO口为高阻态时,就可以