最新日志

发表于:2008-8-19 16:11:48
标签:W79E2051  W79E4051  脱机  烧录器  

0

W79E2051/W79E4051脱机下载烧录器

点击开大图

制作一片没有加密的母片W79E2051/W79E4051,即可批量拷贝程序,拷贝程序后自动加密。极大的方便了客户量产烧录芯片,不占用电脑,在生产线上使用非常方便。操作简单,放入芯片自动识别烧录。

点击此处查看原文 >>

系统分类: 单片机   |    用户分类:    |    来源: 原创

评论(0) | 阅读(54)
发表于:2008-8-19 16:09:19
标签:W79A9311  华邦  芯唐  恒森  脱机  烧录  

0

W79A9311脱机下载烧录器编程器

点击开大图

制作一片没有加密的母片W79A9311,即可批量拷贝程序,拷贝程序后自动加密。极大的方便了客户量产烧录芯片,不占用电脑,在生产线上使用非常方便。操作简单,放入芯片自动识别烧录。

点击此处查看原文 >>

系统分类: 单片机   |    用户分类:    |    来源: 原创

评论(0) | 阅读(44)
发表于:2008-7-18 14:35:52
标签:无标签

0

红印,何时再见你

7月12日,一班茶友在水韵兄店里举行了一场我们喝茶以来最腐败的一场茶会;
在人没到齐之前,先用07年的莽枝古树和07年的麻黑润喉,2泡都是秋茶,现已甜蜜迷人;
人到的差不多了,平时难得喝到的80年代的厚纸8582先登场,果然不俗,香、韵迷人;
后来泡2泡8653,一泡相对干,一泡相对湿,2泡各有特色,算是80年代经典茶品;
最后重头戏当然属于50年代的红印了,这种喝一泡少一泡的茶,真是难得啊。
最后,喝的大家都做不住了,纷纷站起来活动;这次喝的茶可真是价值不菲啊,可算历史上最腐败的一次了;
等待下一次;
红印啊,何时在见你??

点击此处查看原文 >>

系统分类: 生活点滴   |    用户分类:    |    来源: 原创

评论(0) | 阅读(76)
发表于:2008-7-17 10:38:23
标签:watch  dog  看门狗  C51  

0

w79a9311 看门狗 范例程序

/****************************************************************************/
/*     深圳恒森微电子有限公司  (华邦单片机香港及中国区代理商)          */
/*     香港恒森科技有限公司    (华邦单片机香港及中国区代理商)          */
/*     陈文    email:chenwen@hengsen.cn (有 bug 请提交)                   */
/****************************************************************************/
/*  文件名: wdt.c                */
/* 版本     1.0            */
/*  创建日期:    2008-7-17 10:05         */
/*  概述: 本文件为 w79A9311 watch dog 软件        */
/*--------------------------------------------------------------------------*/
/*  历史修改记录:               */
/*  名字                   日期                   注释      */
/*  陈文                   2008-7-17 10:05        ver 1.0     */
/****************************************************************************/

#include "W79A9311.H"

void SetWDT_Time(unsigned char TimeSel)
{
   TA=0xaa;
    TA="0x55";
    WDCON &= ~0x30;
    TA="0xaa";
    TA="0x55";
    WDCON |= (TimeSel & 0x03)<<4;
}

void Start_WDT(void)
{
   TA=0xaa;
    TA="0x55";
    WDCON="0";
    TA="0xaa";
    TA="0x55";
    WDCON |=0x83;
}

void CLR_WDT(void)
{
    TA="0xaa";
    TA="0x55";
    WDCON |= 0x01;
}

void Disable_WDT(void)
{
    TA="0xaa";
    TA="0x55";
    WDCON &= ~0x82;
}

void main(void)
{
 unsigned int i;
 P07 = 0;
 for(i=0;i<0xfff0;i++);
 P07 = 1;
 SetWDT_Time(3);
 Start_WDT();
 CLR_WDT();
 while(1)
 {
  //CLR_WDT();
  for(i=0;i<0xff;i++);
 }
 
}

点击此处查看原文 >>

系统分类: 单片机   |    用户分类:    |    来源: 原创

评论(0) | 阅读(81)
发表于:2008-7-14 15:41:29
标签:W79A9311  EEPROM  NVM  DATA  FLASH  

0

w79a9311 内部 NVM DATA FLASH 范例

/****************************************************************************/
/*     深圳恒森微电子有限公司  (华邦单片机香港及中国区代理商)          */
/*     香港恒森科技有限公司    (华邦单片机香港及中国区代理商)          */
/*     陈文    email:chenwen@hengsen.cn (有 bug 请提交)                   */
/****************************************************************************/
/*  文件名: nvmm.c                  */
/* 版本     1.0            */
/*  创建日期:    2008-7-14 13:47         */
/*  概述: 本文件为 w79A9311 NVM DATA FLASH 软件       */
/*--------------------------------------------------------------------------*/
/*  历史修改记录:               */
/*  名字                   日期                   注释      */
/*  陈文                   2008-7-14 13:47        ver 1.0     */
/****************************************************************************/
#include "W79A9311.H"
unsigned char code  NVMArry[128] _at_ 0xFC00;

void ErasePage(unsigned char ErasePage_num)
{
 NVMADDRH=0x00;
  switch(ErasePage_num)
  {
     case 0: NVMADDRL="0x00";break;
        case 1: NVMADDRL="0x10";break;
        case 2: NVMADDRL="0x20";break;
        case 3: NVMADDRL="0x30";break;
        case 4: NVMADDRL="0x40";break;
        case 5: NVMADDRL="0x50";break;
        case 6: NVMADDRL="0x60";break;
        case 7: NVMADDRL="0x70";break;
        default: break;
    }
    NVMCON|=0x80;    //about 5ms
}

void WriteByte(unsigned char NVM_WAddr,unsigned char NVM_WData)
{
    NVMDAT=NVM_WData;
    NVMADDRH=0x0;
    NVMADDRL="NVM"_WAddr;
    NVMCON|=0x40;
}

unsigned char ReadByte(unsigned char NVM_WAddr)
{
    return NVMArry[NVM_WAddr];
}

void main(void)
{
 while(1)
 {
  ;
 }
 
}

点击此处查看原文 >>

系统分类: 单片机   |    用户分类:    |    来源: 原创

评论(0) | 阅读(79)
发表于:2008-7-14 13:50:36
标签:BUZZER  蜂鸣器  

0

芯唐(华邦)W79A9311 蜂鸣器驱动范例程序

/****************************************************************************/
/*     深圳恒森微电子有限公司  (华邦单片机香港及中国区代理商)          */
/*     香港恒森科技有限公司    (华邦单片机香港及中国区代理商)          */
/*     陈文    email:chenwen@hengsen.cn (有 bug 请提交)                   */
/****************************************************************************/
/*  文件名: buzcon.c              */
/* 版本     1.0            */
/*  创建日期:    2008-7-14 13:47         */
/*  概述: 本文件为 w79A9311 BUZZER 软件         */
/*--------------------------------------------------------------------------*/
/*  历史修改记录:               */
/*  名字                   日期                   注释      */
/*  陈文                   2008-7-14 13:47        ver 1.0     */
/****************************************************************************/

#include "W79A9311.H"

#define  BuzzOutPutEn AUXR1 |= 0x02;
#define  BuzzOutPutDis AUXR1 &= ~0x02;
#define  BuzzInit  {P1M1 &= ~0x01;P1M2 |= 0x01;P10=1;}


void BuzFreqDiv(unsigned char Div)
{
 BUZCON = Div & 0x3f;
}


void main()
{
 BuzzInit;
 BuzFreqDiv(46);  //12M晶振,大概输出1K频率方波
 BuzzOutPutEn;
 while(1);
 {
  ;
 }
 
}

点击此处查看原文 >>

系统分类: 单片机   |    用户分类:    |    来源: 原创

评论(0) | 阅读(81)
发表于:2008-7-14 12:41:34
标签:W79A9311  单片机  AD  芯唐  华邦  

0

芯唐(华邦)W79A9311 AD转换C51范例程序

/****************************************************************************/
/*     深圳恒森微电子有限公司  (华邦单片机香港及中国区代理商)          */
/*     香港恒森科技有限公司    (华邦单片机香港及中国区代理商)          */
/*     陈文    email:chenwen@hengsen.cn (有 bug 请提交)                   */
/****************************************************************************/
/*  文件名: adc.c              */
/* 版本     1.0            */
/*  创建日期:    2007-10-29 10:58        */
/*  概述: 本文件为 w79a9311 ADC 测试 软件         */
/*--------------------------------------------------------------------------*/
/*  历史修改记录:               */
/*  名字                   日期                   注释      */
/*  陈文                   2008-7-14 11:11        ver 1.0     */
/****************************************************************************/
#include "W79A9311.H"

#define uint8 unsigned char
uint8 led[2];
//led code 共阳极       0    1   2    3    4    5    6    7    8     9   a     b   c     d    e   f    灭  高位先出  bit顺序 h,g,f,e,d,c,b,a : Q1--a.....Q8--h
//uint8 code tab[17] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0x0a,0x86,0x8e,0xff};
uint8 code tab[17] = {0x41,0xf5,0x0d,0x15,0xb1,0x13,0x03,0xd5,0x01,0x11,0x81,0x83,0xc6,0x0a,0x86,0x8e,0xff};

sbit Csg1 = P1^6;   
sbit Csg0 = P1^7; 


#define  SEL_ADC_CLK_Div1  {ADCCON1 &= 0x04;}
#define  SEL_ADC_CLK_Div2  {ADCCON1 &= 0x04;ADCCON1 |= 0x40;}
#define  SEL_ADC_CLK_Div4  {ADCCON1 &= 0x04;ADCCON1 |= 0x80;}

#define  EnADCExtTrig  ADCCON |= 0x20;
#define  DisADCExtTrig  ADCCON &= ~0x20;
#define  SelADC_RC_Clk  ADCCON |= 0x04;
#define  SelADC_CPU_Clk  ADCCON &= ~0x04;
#define  EnableADC   AUXR1 |= 0x04;
#define  DisableADC   AUXR1 &= ~0x04;
#define     StartADC            {ADCCON&=0xef; ADCCON|=0x08;}
//ADCCON  --ADCI中断请求位 --ADCS开始转换位
//当A/D准备好时ADCI被设置,当ADCI被设置,则ADCS自动清0
//若ADCI为高电平,不能再次作AD转换,若ADC中断允许则ADCI被自动清除

uint8 HexBcd(uint8 h);
void Display(void);

void Dispv(v)
{
 uint8 temp1; 
 temp1 = HexBcd(v); 
 led[0] = (temp1&0x0f);
 led[1] = (temp1&0xf0)>>4; 
 Display();
}

void Display(void)
{
 bit  B_disp_flag; 
 uint8 temp;
 Csg1 = 1;
 Csg0 = 1;
 if(B_disp_flag == 1)
 {
  B_disp_flag = 0;
  temp = led[0];
  temp = tab[temp];
  P0 &= 0xe0;
  P0 |= (temp&0x1f);
  P1 &= 0xe3;
  P1 |= ((temp >> 3)&0x1c);
  Csg1 = 1;
  Csg0 = 0;
 }
 else
 {
  B_disp_flag = 1;
  temp = led[1];
  temp = tab[temp]&0xfe;  //小数点
  P0 &= 0xe0;
  P0 |= (temp&0x1f);
  P1 &= 0xe3;
  P1 |= ((temp >> 3)&0x1c);
  Csg0 = 1;
  Csg1 = 0;
 } 
}

uint8 HexBcd(uint8 h)
{
 uint8 b;
 if(h > 99) return 0x99;
 b=h/10*0x10 + h%10;
 return b;
}

 

//禁止数字输入 
void DisChannelInput(unsigned char Channel)
{
 switch(Channel)
    {
     case 0:PADIDS |= 0x01;break;
     case 1:PADIDS |= 0x02;break;
     case 2:PADIDS |= 0x04;break;
      case 3:PADIDS |= 0x08;break;
      case 4:PADIDS |= 0x10;break;
     case 5:PADIDS |= 0x20;break;
     case 6:PADIDS |= 0x40;break;
      case 7:PADIDS |= 0x80;break;
     default: break;
    }
}

//打开数字输入
void EnChannelInput(unsigned char Channel)
{
 switch(Channel)
    {
     case 0:PADIDS &= ~0x01;break;
     case 1:PADIDS &= ~0x02;break;
     case 2:PADIDS &= ~0x04;break;
      case 3:PADIDS &= ~0x08;break;
      case 4:PADIDS &= ~0x10;break;
     case 5:PADIDS &= ~0x20;break;
     case 6:PADIDS &= ~0x40;break;
      case 7:PADIDS &= ~0x80;break;
     default: break;
    }
}

unsigned int Read_ADC(unsigned char channel)
{
    unsigned int temp;
    EnableADC;
    ADCCON1 &= ~0x04;
 switch(channel)
    {
     case 0:P0M1|=0x08;P0M2&=~0x08;ADCCON=0; P0|=0x08;break;
     case 1:P0M1|=0x10;P0M2&=~0x10;ADCCON=1; P0|=0x10;break;
     case 2:P0M1|=0x20;P0M2&=~0x20;ADCCON=2; P0|=0x20;break;
      case 3:P0M1|=0x40;P0M2&=~0x40;ADCCON=3; P0|=0x40;break;

      case 4:P0M1|=0x04;P0M2&=~0x04;ADCCON=0;ADCCON1|=0x04;P0|=0x04;break;
     case 5:P0M1|=0x02;P0M2&=~0x02;ADCCON=1;ADCCON1|=0x04;P0|=0x02;break;
     case 6:P0M1|=0x01;P0M2&=~0x01;ADCCON=2;ADCCON1|=0x04;P0|=0x01;break;
      case 7:P0M1|=0x80;P0M2&=~0x80;ADCCON=3;ADCCON1|=0x04;P0|=0x80;break;
     default: break;
    }
    ADCCON&=0xef;
    ADCCON|=0x08;//start ADC
    while((ADCCON&0x18)==0x08);//查询,(可用中断实现)
  ADCCON&=0xe7;

    temp="ADCH";
    temp <<=2;
    temp |=(ADCCON >> 6);
    return temp;
}

//测试通过
void main(void)
{
 unsigned int temp,i;
 unsigned char adc_v;
 SEL_ADC_CLK_Div1;
 
 while(1)
 {
  temp=Read_ADC(2);
  adc_v = temp*50/1024;
  Dispv(adc_v);
  for(i=0;i<0xfff0;i++);
  //for(i=0;i<0xfff0;i++);
 }
 
}

点击此处查看原文 >>

系统分类: 单片机   |    用户分类:    |    来源: 原创

评论(0) | 阅读(109)
发表于:2008-7-4 10:48:53
标签:无标签

0

华邦电子将更名为芯唐科技

2008年7月,华邦电子旗下逻辑IC事业部将成为独立公司,新公司名称在中国大陆为“芯唐”,在台湾地区为“新唐”。华邦电子的MCU业务将划归新成立的公司经营。在2008年,华邦(芯唐)的MCU新产品将突出两大主题:一是将一般8051标准产品提升至工业规格,同时改进并提升保密功能;二是LPC(低管脚)产品的推广,此类技术将在小家电、电源管理、电动自行车、电动工具和马达控制等领域都会有相对应的MCU产品推出。
原华邦LOGO:

芯唐科技LOGO:



点击此处查看原文 >>

系统分类: 单片机   |    用户分类:    |    来源: 原创

评论(0) | 阅读(177)
发表于:2008-7-4 10:38:18
标签:W25X40  51单片机读写程序  

0

华邦串行FLASH W25X40 读写程序范例

适用于华邦W25X系列,单通道模式;

/****************************************************************************/
/*     深圳恒森微电子有限公司  (华邦单片机香港及中国区代理商)          */
/*     香港恒森科技有限公司    (华邦单片机香港及中国区代理商)          */
/*     陈文    email:chenwen@hengsen.cn (有 bug 请提交)                   */
/****************************************************************************/
/*  文件名: spidrv.c              */
/* 版本     1.0            */
/*  创建日期:    2007-10-29 10:58        */
/*  概述: 本文件为 w79e823   读写 SPI flash程序       */
/*--------------------------------------------------------------------------*/
/*  历史修改记录:               */
/*  名字                   日期                   注释      */
/*  陈文                   2007.10.28           ver 1.0      */
/****************************************************************************/
#include <w79e825.h>
#include <intrins.h>
#define uint8 unsigned char
#define uint16 unsigned int
#define uchar unsigned char
#define uint unsigned int
#define uint32 unsigned long

sbit _cs= P1^2;
sbit _do= P1^3;
sbit _wp= P1^4;
//sbit _hold= P1^5;
sbit _clk= P1^6;
sbit _di= P1^7;

#define W25P_WriteEnable 0x06
#define W25P_WriteDisable 0x04
#define W25P_ReadStatusReg 0x05
#define W25P_WriteStatusReg 0x01
#define W25P_ReadData  0x03
#define W25P_FastReadData 0x0B
#define W25P_PageProgram 0x02
#define W25P_SectorErase 0xD8 // 64KB
#define W25P_ChipErase  0xC7
#define W25P_PowerDown  0xB9
#define W25P_ReleasePowerDown 0xAB
#define W25P_DeviceID  0xAB
#define W25P_ManufactDeviceID 0x90
 
void init_cpu(void);
void IO_Send_Byte(uchar out);
uchar IO_Get_Byte();
void delay(uchar tt);
void IO_Wait_Busy();
void IO_init();
uchar IO_Read_StatusReg();
void IO_Write_StatusReg(byte);
void IO_Write_Enable();
void IO_PowerDown();
void IO_ReleasePowerDown();
uchar IO_Read_ID1();
uint IO_Read_ID2(uchar ID_Addr);
uchar IO_Read_Byte(uint32 Dst_Addr);
void IO_Read_nBytes(uint32 Dst_Addr, uchar nBytes_128);
uchar IO_FastRead_Byte(uint32 Dst_Addr);
void IO_FastRead_nBytes(uint32 Dst_Addr, uchar nBytes_128);
void IO_Write_Byte(uint32 Dst_Addr, uchar byte);
void IO_Write_nBytes(uint32 Dst_Addr, uchar nBytes_128);
void IO_Erase_Chip();
void IO_Erase_Sector(uint32 Dst_Addr);
void Verify(uchar byte, uchar cor_byte);
void IO_Write_Disable();
void trace(uchar *str,uchar len);
uint IO_Read_ID3();

uint8 Rxtemp;
bit MYTI;
uint8 tx_buff[16];
uint8 upper_128[16];
bit rx_ok;
#define nop() _nop_()

void main(void)

 uint i;
 
 init_cpu(); 
 IO_init();
 for(;;)
 {   
  if(rx_ok == 1)
  {
   rx_ok = 0;
   switch(Rxtemp)
   {
    case 0x01:
     Rxtemp = 0;
     tx_buff[0] = IO_Read_ID1();
     trace(tx_buff,1);
     break;
    case 0x02:
    i = IO_Read_ID2(0x00);
    tx_buff[1] = (uchar)i;
    tx_buff[0] = (uchar)(i>>8);
    trace(tx_buff,2);
    
    break;
    case 0x03:
    i = IO_Read_ID3();
    tx_buff[1] = (uchar)i;
    tx_buff[0] = (uchar)(i>>8);
    trace(tx_buff,3);
    break;
    case 0x04:
    tx_buff[0] = IO_Read_Byte(0x00000000);
    trace(tx_buff,1);
    break;
    case 0x05:
    tx_buff[0] = 0x55;
    IO_Write_Byte(0x00000000,0xa5);
    trace(tx_buff,1);
    break;
    case 0x06:
    tx_buff[0] = IO_Read_StatusReg();
    trace(tx_buff,1);
    break;
    case 0x07:
    IO_Write_Enable(); 
    break;
    case 0x08:
    upper_128[0]=0x01;upper_128[1]=0x02;upper_128[2]=0x03;upper_128[3]=0x04;
    IO_Write_nBytes(0x00000000,4);
    
    break;
    case 0x09:
    IO_Erase_Chip();
    break;
    case 0x0a:
    IO_Erase_Sector(0x00000000);
    break;
    default:
    break;
   }
   
  }
  
   
 }
}

void init_cpu(void)
{  
 TMOD = 0x21;   
 PCON = PCON | 0x80;  //波特率加倍
 //CKCON = 0x10;           //定时器1采用4分频
 SCON  = 0x50;   //异步、10位、波特率可变,无校验位
 TH1   = 0xf8;            //在15M晶振下,波特率是9600,
    TL1   = 0xf8;   
    TR1   = 1;     //T1 timer run
    ES    = 1;    //uart interrupt enable 
 EA = 1;     //all interrupt enable
 
}


//串口中断程序
void UART_isr(void) interrupt 4
{
 if(RI)
    {
        RI = 0;
        Rxtemp = SBUF;   //接收
        //SBUF = Rxtemp;   //发送
        rx_ok = 1;
  return;
 }
 if(TI)
 {
  TI = 0;
  MYTI = 1;  
  }
}

void IO_Send_Byte(uchar out)
{
 uchar i = 0; 
 _cs = 0;
 for (i = 0; i < 8; i++)
 {
  if ((out & 0x80) == 0x80) /* check if MSB is high */
   _di = 1;
  else
   _di = 0;  /* if not, set to low */
  _clk = 1;   /* toggle clock high */
  out = (out << 1);  /* shift 1 place for next bit */
  nop();nop();nop();nop();
  _clk = 0;   /* toggle clock low */
 }
}

uchar IO_Get_Byte()
{
 uchar i = 0, in = 0, temp = 0; 
 _cs = 0;
 for (i = 0; i < 8; i++)
 {
  in = (in << 1);  /* shift 1 place to the left or shift in 0 */
  temp = _do;  /* save input */
  _clk = 1;  /* toggle clock high */
  if (temp == 1)  /* check to see if bit is high */
   in |= 0x01; /* if high, make bit high */
  _clk = 0;  /* toggle clock low */
 } 
 return in;
}

void delay(uchar tt)
{
 while(tt--);
}

void IO_Wait_Busy()
{
/*  waste time until not busy WEL & Busy bit all be 1 (0x03). */
 while (IO_Read_StatusReg() == 0x03)
  IO_Read_StatusReg();
}

void IO_init()
{
 _clk = 0; /* set clock to low initial state for SPI operation mode 0 */
// _clk = 1; /* set clock to low initial state for SPI operation mode 3 */
// _hold = 1;
 _wp = 1;
 _cs = 1;
 
 IO_Write_Disable();
 
}

uchar IO_Read_StatusReg()
{
 uchar byte = 0;
 _cs = 0;   /* enable device */
 IO_Send_Byte(W25P_ReadStatusReg); /* send Read Status Register command */
 byte = IO_Get_Byte();   /* receive byte */
 _cs = 1;    /* disable device */
 
 return byte;
}

void IO_Write_StatusReg(byte)
{
 _cs = 0;    /* enable device */
 IO_Send_Byte(W25P_WriteStatusReg); /* select write to status register */
 IO_Send_Byte(byte); /* data that will change the status(only bits 2,3,7 can be written) */
 _cs = 1;    /* disable the device */
}

void IO_Write_Enable()
{
 _cs = 0;   /* enable device */
 IO_Send_Byte(W25P_WriteEnable); /* send W25P_Write_Enable command */
 _cs = 1;   /* disable device */
}

void IO_PowerDown()
{
 _cs = 0;;    /* enable device */
 IO_Send_Byte(W25P_PowerDown);  /* send W25P_PowerDown command 0xB9 */
 _cs = 1;;    /* disable device */
 delay(6);    /* remain CS high for tPD = 3uS */
}

void IO_ReleasePowerDown()
{
 _cs = 0;   /* enable device */
 IO_Send_Byte(W25P_ReleasePowerDown); /* send W25P_PowerDown command 0xAB */
 _cs = 1;    /* disable device */
 delay(6);    /* remain CS high for tRES1 = 3uS */
}

uchar IO_Read_ID1()
{
 uchar byte;
 _cs = 0;  /* enable device */
 IO_Send_Byte(W25P_DeviceID); /* send read device ID command (ABh) */
    IO_Send_Byte(0);  /* send address */
 IO_Send_Byte(0);  /* send address */
 IO_Send_Byte(0);  /* send 3_Dummy address */
 byte = IO_Get_Byte();  /* receive Device ID byte */
 
 _cs  = 1;   /* disable device */
 delay(4);   /* remain CS high for tRES2 = 1.8uS */

 return byte;
}

uint IO_Read_ID2(uchar ID_Addr)
{
 uint IData16;
 _cs = 0;   /* enable device */
 IO_Send_Byte(W25P_ManufactDeviceID); /* send read ID command (90h) */
    IO_Send_Byte(0x00);   /* send address */
 IO_Send_Byte(0x00);   /* send address */
 IO_Send_Byte(ID_Addr);   /* send W25Pxx selectable ID address 00H or 01H */
 IData16 = IO_Get_Byte()<<8;  /* receive Manufature or Device ID byte */
 IData16 |= IO_Get_Byte();  /* receive Device or Manufacture ID byte */
 _cs = 1;    /* disable device */
 
 return IData16;
}

uint IO_Read_ID3()
{
 uint IData16;
 _cs = 0;   /* enable device */
 IO_Send_Byte(0x9f); /* send read ID command (90h) */
   
 IData16 = IO_Get_Byte()<<8;  /* receive Manufature or Device ID byte */
 IData16 |= IO_Get_Byte();  /* receive Device or Manufacture ID byte */
 tx_buff[2] = IO_Get_Byte(); 
 _cs = 1;    /* disable device */
 
 return IData16;
}

uchar IO_Read_Byte(uint32 Dst_Addr)
{
 uchar byte = 0; 

 _cs = 0;     /* enable device */
 IO_Send_Byte(W25P_ReadData);    /* read command */
 IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16)); /* send 3 address bytes */
 IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 IO_Send_Byte(Dst_Addr & 0xFF);
 byte = IO_Get_Byte();
 _cs = 1;   /* disable device */
 
 return byte;   /* return one byte read */
}

void IO_Read_nBytes(uint32 Dst_Addr, uchar nBytes_128)
{
 uint32 i = 0;
 
 _cs = 0;     /* enable device */
 IO_Send_Byte(W25P_ReadData);    /* read command */
 IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16));  /* send 3 address bytes */
 IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 IO_Send_Byte(Dst_Addr & 0xFF);
 for (i = 0; i < nBytes_128; i++)  /* read until no_bytes is reached */
 {
  upper_128[i] = IO_Get_Byte(); /* receive byte and store at address 80H - FFH */
 }
 
 _cs = 1;    /* disable device */
 
}

uchar IO_FastRead_Byte(uint32 Dst_Addr)
{
 uchar byte = 0; 

 _cs = 0;     /* enable device */
 IO_Send_Byte(W25P_FastReadData);   /* fast read command */
 IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16)); /* send 3 address bytes */
 IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 IO_Send_Byte(Dst_Addr & 0xFF);
 IO_Send_Byte(0xFF);  /*dummy byte*/
 byte = IO_Get_Byte();
 _cs = 1;   /* disable device */
 
 return byte;   /* return one byte read */
}

void IO_FastRead_nBytes(uint32 Dst_Addr, uchar nBytes_128)
{
 uchar i = 0;
 
 _cs = 0;     /* enable device */
 IO_Send_Byte(W25P_FastReadData);   /* read command */
 IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16));  /* send 3 address bytes */
 IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 IO_Send_Byte(Dst_Addr & 0xFF);
 IO_Send_Byte(0xFF);   /*dummy byte*/
 for (i = 0; i < nBytes_128; i++) /* read until no_bytes is reached */
 {
  upper_128[i] = IO_Get_Byte(); /* receive byte and store at address 80H - FFH */
 }
 _cs = 1;    /* disable device */

}

void IO_Write_Byte(uint32 Dst_Addr, uchar byte)
{
 _cs = 0;     /* enable device */
 IO_Write_Enable();    /* set WEL */
 IO_Wait_Busy();
 
 _cs = 0; 
 IO_Send_Byte(W25P_PageProgram);   /* send Byte Program command */
 IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16)); /* send 3 address bytes */
 IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 IO_Send_Byte(Dst_Addr & 0xFF);
 IO_Send_Byte(byte);   /* send byte to be programmed */
 _cs = 1;    /* disable device */
}

void IO_Write_nBytes(uint32 Dst_Addr, uchar nBytes_128)

 uchar i, byte; 
 _cs = 0;     /* enable device */
 IO_Write_Enable();    /* set WEL */
 _cs = 0;
 IO_Send_Byte(W25P_PageProgram);   /* send Byte Program command */
 IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16)); /* send 3 address bytes */
 IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 IO_Send_Byte(Dst_Addr & 0xFF);
 
 for (i = 0; i < nBytes_128; i++)
 {
  byte = upper_128[i];
  IO_Send_Byte(byte);  /* send byte to be programmed */
 } 
 _cs = 1;    /* disable device */
 
 //printf("\nPage program (%d nBytes)! please waiting....\n");
}

void IO_Erase_Chip()
{
 _cs = 0;    /* enable device */
 IO_Write_Enable();    /* set WEL */
 _cs = 0;
 IO_Wait_Busy();
 _cs = 0;
 IO_Send_Byte(W25P_ChipErase);  /* send Chip Erase command */
 _cs = 1;    /* disable device */
}

void IO_Erase_Sector(uint32 Dst_Addr)
{
 _cs = 0;     /* enable device */
 IO_Write_Enable();    /* set WEL */
 _cs = 0;
 IO_Send_Byte(W25P_SectorErase);   /* send Sector Erase command */
 IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16));  /* send 3 address bytes */
 IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 IO_Send_Byte(Dst_Addr & 0xFF);
 _cs = 1;     /* disable device */
}

void Verify(uchar byte, uchar cor_byte)
{
 if (byte != cor_byte)
 {
  while(1);
   //LED_Error = 0; /* display to view error on LED. */   
 }
}

void IO_Write_Disable()
{
 _cs = 0;    /* enable device */
 IO_Send_Byte(W25P_WriteDisable); /* send W25P_Write_Disable command */
 _cs = 1;    /* disable device */
}

void myputchar(uchar c)

 ES = 0;
 SBUF = c;
 while (TI == 0);
 TI = 0;
 ES = 1;
}

void trace(uchar *str,uchar len)
{
 uint i;
 for(i=0;i<len;i++)
 {
  myputchar(*str);
  str++;
 }
}

 

//IO_Read_StatusReg  Reads the status register of the serial flash
//IO_Write_StatusReg  Performs a write to the status register
//IO_Write_Enable   Write enables the serial flash
//IO_Write_Disable  Write disables the serial flash
//IO_Read_ID1   Reads the device ID using the instruction 0xAB
//IO_Read_ID2   Reads the manufacturer ID and device ID with 0x90
//IO_Read_Byte   Reads one byte from the serial flash and returns byte(max of 20 MHz CLK frequency)
//IO_Read_nBytes   Reads multiple bytes(max of 20 MHz CLK frequency)
//IO_FastRead_Byte  Reads one byte from the serial flash and returns byte(max of 33 MHz CLK frequency)
//IO_FastRead_nBytes  Reads multiple bytes(max of 33 MHz CLK frequency)
//IO_Write_Byte   Program one byte to the serial flash
//IO_Write_nBytes   Program n bytes to the serial flash, n<=256
//IO_Erase_Chip   Erases entire serial flash
//IO_Erase_Sector   Erases one sector (64 KB) of the serial flash
//IO_Wait_Busy   Polls status register until busy bit is low

点击此处查看原文 >>

系统分类: 单片机   |    用户分类:    |    来源: 原创

评论(0) | 阅读(138)
发表于:2008-7-1 13:04:24
评论(0) | 阅读(112)
2345678下一页总共 , 当前 /