虫虫首页|资源下载|资源专辑|精品软件
登录|注册

Void

  • DS1302+AT89S52+LED时钟程序(C语言源代码+

    #include<reg51.h>/*************************ds1302与at89s52引脚连接********************/sbit T_RST=P3^5; sbit T_CLK=P3^6;                 sbit T_IO=P3^7;                                sbit ACC0=ACC^0;sbit ACC7=ACC^7;unsigned char seg[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};         //0~~9段码 /******************DS1302:写入操作(上升沿)*********************/ Void write_byte(unsigned char da){   unsigned char i;   ACC=da;   for(i=8;i>0;i--)   {       T_IO=ACC0;   T_CLK=0;           T_CLK=1;      ACC=ACC>>1;   }} /******************DS1302:读取操作(下降沿)*****************/unsigned char read_byte(Void){   unsigned char i;   for(i=0;i<8;i++)   {      ACC=ACC>>1;   T_CLK = 1;   T_CLK = 0;      ACC7 = T_IO;   }   return(ACC); } /******************DS1302:写入数据(先送地址,再写数据)***************************/ Void write_1302(unsigned char addr,unsigned char da){   T_RST=0;    //停止工作   T_CLK=0;                                    T_RST=1;   //重新工作   write_byte(addr);    //写入地址      write_byte(da);   T_RST=0;   T_CLK=1;}

    标签: 1302 LED DS AT

    上传时间: 2014-01-17

    上传用户:sglccwk

  • DS1820 C51 子程序 (一线数据传输)

    //芯片资料请到www.elecfans.com查找 //DS1820 C51 子程序//这里以11.0592M晶体为例,不同的晶体速度可能需要调整延时的时间//sbit DQ =P2^1;//根据实际情况定义端口 typedef unsigned char byte;typedef unsigned int  word; //延时Void delay(word useconds){  for(;useconds>0;useconds--);} //复位byte ow_reset(Void){  byte presence;  DQ = 0; //pull DQ line low  delay(29); // leave it low for 480us  DQ = 1; // allow line to return high  delay(3); // wait for presence  presence = DQ; // get presence signal  delay(25); // wait for end of timeslot  return(presence); // presence signal returned}     // 0=presence, 1 = no part //从 1-wire 总线上读取一个字节byte read_byte(Void){  byte i;  byte value = 0;  for (i=8;i>0;i--)  {    value>>=1;    DQ = 0; // pull DQ low to start timeslot    DQ = 1; // then return high    delay(1);  //for (i=0; i<3; i++);     if(DQ)value|=0x80;    delay(6); // wait for rest of timeslot  }  return(value);} //向 1-WIRE 总线上写一个字节Void write_byte(char val){  byte i;  for (i=8; i>0; i--) // writes byte, one bit at a time  {    DQ = 0; // pull DQ low to start timeslot    DQ = val&0x01;    delay(5); // hold value for remainder of timeslot    DQ = 1;    val=val/2;  }  delay(5);} //读取温度char Read_Temperature(Void){  union{    byte c[2];    int x;  }temp;   ow_reset();  write_byte(0xCC); // Skip ROM  write_byte(0xBE); // Read Scratch Pad  temp.c[1]=read_byte();  temp.c[0]=read_byte();  ow_reset();  write_byte(0xCC); //Skip ROM  write_byte(0x44); // Start Conversion  return temp.x/2;}

    标签: 1820 C51 DS 程序

    上传时间: 2013-11-03

    上传用户:hongmo

  • 串行编程器源程序(Keil C语言)

    串行编程器源程序(Keil C语言)//FID=01:AT89C2051系列编程器//实现编程的读,写,擦等细节//AT89C2051的特殊处:给XTAL一个脉冲,地址计数加1;P1的引脚排列与AT89C51相反,需要用函数转换#include <e51pro.h> #define C2051_P3_7 P1_0#define C2051_P1 P0//注意引脚排列相反#define C2051_P3_0  P1_1#define C2051_P3_1 P1_2#define C2051_XTAL P1_4#define C2051_P3_2 P1_5#define C2051_P3_3 P1_6#define C2051_P3_4 P1_7#define C2051_P3_5 P3_5 Void InitPro01()//编程前的准备工作{ SetVpp0V(); P0=0xff; P1=0xff; C2051_P3_5=1; C2051_XTAL=0; Delay_ms(20); nAddress=0x0000; SetVpp5V();} Void ProOver01()//编程结束后的工作,设置合适的引脚电平{ SetVpp5V(); P0=0xff; P1=0xff; C2051_P3_5=1; C2051_XTAL=1;} BYTE GetData()//从P0口获得数据{ B_0=P0_7; B_1=P0_6; B_2=P0_5; B_3=P0_4; B_4=P0_3; B_5=P0_2; B_6=P0_1; B_7=P0_0; return B;} Void SetData(BYTE DataByte)//转换并设置P0口的数据{ B=DataByte; P0_0=B_7; P0_1=B_6; P0_2=B_5; P0_3=B_4; P0_4=B_3; P0_5=B_2; P0_6=B_1; P0_7=B_0;} Void ReadSign01()//读特征字{ InitPro01(); Delay_ms(1);//----------------------------------------------------------------------------- //根据器件的DataSheet,设置相应的编程控制信号 C2051_P3_3=0; C2051_P3_4=0; C2051_P3_5=0; C2051_P3_7=0; Delay_ms(20); ComBuf[2]=GetData(); C2051_XTAL=1; C2051_XTAL=0; Delay_us(20); ComBuf[3]=GetData(); ComBuf[4]=0xff;//----------------------------------------------------------------------------- ProOver01();} Void Erase01()//擦除器件{ InitPro01();//----------------------------------------------------------------------------- //根据器件的DataSheet,设置相应的编程控制信号 C2051_P3_3=1; C2051_P3_4=0; C2051_P3_5=0; C2051_P3_7=0; Delay_ms(1); SetVpp12V(); Delay_ms(1); C2051_P3_2=0; Delay_ms(10); C2051_P3_2=1; Delay_ms(1);//----------------------------------------------------------------------------- ProOver01();} BOOL Write01(BYTE Data)//写器件{//----------------------------------------------------------------------------- //根据器件的DataSheet,设置相应的编程控制信号 //写一个单元 C2051_P3_3=0; C2051_P3_4=1; C2051_P3_5=1; C2051_P3_7=1; SetData(Data); SetVpp12V(); Delay_us(20); C2051_P3_2=0; Delay_us(20); C2051_P3_2=1; Delay_us(20); SetVpp5V(); Delay_us(20); C2051_P3_4=0; Delay_ms(2); nTimeOut=0; P0=0xff; nTimeOut=0; while(!GetData()==Data)//效验:循环读,直到读出与写入的数相同 {  nTimeOut++;  if(nTimeOut>1000)//超时了  {   return 0;  } } C2051_XTAL=1; C2051_XTAL=0;//一个脉冲指向下一个单元//----------------------------------------------------------------------------- return 1;} BYTE Read01()//读器件{ BYTE Data;//----------------------------------------------------------------------------- //根据器件的DataSheet,设置相应的编程控制信号 //读一个单元 C2051_P3_3=0; C2051_P3_4=0; C2051_P3_5=1; C2051_P3_7=1; Data=GetData(); C2051_XTAL=1; C2051_XTAL=0;//一个脉冲指向下一个单元//----------------------------------------------------------------------------- return Data;} Void Lock01()//写锁定位{ InitPro01();//先设置成编程状态//----------------------------------------------------------------------------- //根据器件的DataSheet,设置相应的编程控制信号 if(ComBuf[2]>=1)//ComBuf[2]为锁定位 {  C2051_P3_3=1;  C2051_P3_4=1;  C2051_P3_5=1;  C2051_P3_7=1;  Delay_us(20);  SetVpp12V();  Delay_us(20);  C2051_P3_2=0;  Delay_us(20);  C2051_P3_2=1;  Delay_us(20);  SetVpp5V(); } if(ComBuf[2]>=2) {  C2051_P3_3=1;  C2051_P3_4=1;  C2051_P3_5=0;  C2051_P3_7=0;  Delay_us(20);  SetVpp12V();  Delay_us(20);  C2051_P3_2=0;  Delay_us(20);  C2051_P3_2=1;  Delay_us(20);  SetVpp5V(); }//----------------------------------------------------------------------------- ProOver01();} Void PreparePro01()//设置pw中的函数指针,让主程序可以调用上面的函数{ pw.fpInitPro=InitPro01; pw.fpReadSign=ReadSign01; pw.fpErase=Erase01; pw.fpWrite=Write01; pw.fpRead=Read01; pw.fpLock=Lock01; pw.fpProOver=ProOver01;}

    标签: Keil 串行 C语言 编程器

    上传时间: 2013-11-11

    上传用户:gut1234567

  • 用C51写的普通拼音输入法源程序代码

    用C51写的普通拼音输入法源程序代码:原作使用了一个二维数组用以查表,我认为这样比较的浪费空间,而且每个字表的索引地址要手工输入,效率不高。所以我用结构体将其改写了一下。就是大家现在看到的这个。  因为代码比较的大,共有6,000多汉字,这样就得要12,000 byte来存放GB内码,所以也是没办法的.编译结果约为3000h,因为大部分是索引表,代码优化几乎无效。    在Keil C里仿真芯片选用的是华邦的W77E58,它有32k ROM, 256B on-chip RAM, 1K on-chip SRAM (用DPTR1指针寻址,相当于有1K的片上xdata)。条件有限,没有上片试验,仿真而已。  打算将其移植到AVR上,但CodeAVRC与IAR EC++在结构体、指针的定义使用上似乎与C51不太一样,现在还未搞定。还希望在这方面有经验的网友能给予指导。 #include<stdio.h> char * py_ime(char *); Void main(Void){ while(1)    {     char input_string[]="yI";     xdata char chinese_string[255];     sprintf(chinese_string,"%s",py_ime(input_string));    }}

    标签: C51 拼音输入法 代码 源程序

    上传时间: 2013-10-30

    上传用户:cainaifa

  • 采用18b20芯片的温度测量C51源程序

    #include <reg51.h>#include<intrins.h> #define   BUSY1    (DQ1==0) sbit      DQ1    =  P0^4; unsigned char idata TMP; unsigned char idata TMP_d; unsigned char f; Void wr_ds18_1(char dat);unsigned char rd_ds18_1(); /***************延时程序,单位us,大于10us*************/Void time_delay(unsigned char time){   time=time-10;  time=time/6;  while(time!=0)time--;} /*****************************************************//*                reset ds18b20                      *//*****************************************************/Void ds_reset_1(Void){  unsigned char idata count=0;    DQ1=0;   time_delay(240); time_delay(240);  DQ1=1;  return;}

    标签: 18b20 C51 芯片 温度测量

    上传时间: 2013-10-28

    上传用户:sssnaxie

  • 24c01a的读写程序

    #include <at24c01a.h>/*************************************************向24C01A写入一个字节输入:E2ROM地址,字节数据******************************************************/Void write24c01a(uchar uadd_1,uchar udata_1){sendbyte=0xa0;start();send(sendbyte);if (!ack())continue;send(uadd_1);if (!ack())continue;send(udata_1)if (!ack())continue;stop();}/**********************************发送开始*****************************************/Void start(Void){a_scl=1;a_sda=1;a_sda=0;a_scl=0;a_scl=1;}/********************************************发送停止*******************************************/Void stop(Void){a_scl=0;a_sda=0;a_scl=1;a_sda=1;} /*********************************************发送反馈************************************************/bit ack(Void){int a_acka_scl=0;a_scl=0;a_scl=0;a_scl=1;a_ack=a_sda;a_scl=0;return(a_ack)}/**************************************发送无反馈********************************************/bit noack(Void){int a_ack;a_scl=1;a_scl=1;a_scl=0;}/*******************************************发送****************************************************/Void send(uchar  undata){uchar i;sendbyte=undatafor(i=8;i>0;i--){a_sda=sendbyte7;a_scl=0;a_scl=1;sendbyte=sendbyte<<1}}/********************************************接受****************************************************/ Void   receive(Void){int i;uchar data;for(i=8;i>0;i--){ a_scl=1;receivebyte7=a_sda;a_scl=0;receivebyte=receivebyte>>1}receivedata=receivebyte;}/********************************************向 24c01a读一个字节;输入:EEROM地址;输出:EEROM数据;********************************************/Void read24c01a(uchar  counter){receivebyte=0xa1;start();send(receivebyte);if (!ack())continue;send(counter);if (!ack())continue;receive()noack();stop();}

    标签: 24c01a 读写程序

    上传时间: 2013-12-23

    上传用户:wxhwjf

  • 24c16读写驱动程序

    24c16读写驱动程序,//=-------------------------------------------------------------------------------/*模块调用:读数据:read(unsigned int address)写数据:write(unsigned int address,unsigned char dd)   dd为要写的 数据字节*///------------------------------------------------------------------------------ sbit sda=P3^0;sbit scl=P3^1; sbit a0=ACC^0;                  //定义ACC的位,利用ACC操作速度最快sbit a1=ACC^1;sbit a2=ACC^2;sbit a3=ACC^3;sbit a4=ACC^4;sbit a5=ACC^5;sbit a6=ACC^6;sbit a7=ACC^7; //------------------------------------------------------------------------------#pragma disableVoid s24(Void)                 //起始函数{_nop_();    scl=0;     sda=1;    scl=1;    _nop_();    sda=0;    _nop_();    _nop_();    scl=0;     _nop_();    _nop_();    sda=1;} //------------------------------------------------------------------------------#pragma disableVoid p24(Void)                 //停止函数{sda=0;    scl=1;    _nop_();    _nop_();    sda=1;} //-----------------------------------------------------------------------------#pragma disableunsigned char rd24(Void) /////////////////从24c16读一字节数据{       ACC=0x00;sda=1;scl=1;a7=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a6=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a5=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a4=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a3=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a2=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a1=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a0=sda;_nop_();_nop_();_nop_();_nop_();scl=0;sda=1;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0; /// ///////////////24c16的一位回答位。return(ACC);}//------------------------------------------------------------------------------#pragma disableVoid wd24(unsigned char dd) ////////////////向24c16写一字节数据{      sda=1;ACC=dd;sda=a7;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a6;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a5;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a4;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a3;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a2;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a1;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a0;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=0;scl=1;//scl=0;(在下面程序中)}//---------------------------------------------------------------------------#pragma disableunsigned char read(unsigned int address){unsigned char dd;    s24();                        ////////////////////////开始条件    wd24(0xa0);                /////////////////////////写器件地址(写命令)     _nop_();_nop_();_nop_();_nop_();      scl=0;                        ///////////////////////////////////接收器件地址确认信号    wd24(address);                //////////////////////////// 写数据地址    _nop_();_nop_();_nop_();_nop_();    scl=0;s24();                             ///////////////////////////////////开始条件    wd24(0xa1);                 /////////////////////////////写器件地址(读命令)    scl=0;    dd=rd24();              //////////////////////////////////读 一字节    p24();                   ////////////////////////////////////停止条件    return(dd);}//------------------------------------------------------------------------------#pragma disableVoid write(unsigned int address,unsigned char dd){s24();                        /////////////////开始条件    wd24(0xa0);            ////////////////////////写器件地址;    scl=0;     wd24(address);              /////////////////////写数据地址    scl=0;    wd24(dd);                  //////////////////////////写dd数据    scl=0;    p24();                      /////////////////////////停止条件;  }          

    标签: 24c16 读写 驱动程序

    上传时间: 2013-11-18

    上传用户:墙角有棵树

  • RD系列微型打印机打印实例

    C51控制并口打印机实例:/* 沈阳新荣达电子 *//* 2004-12-7 */#include <reg52.h>#define uchar unsigned char#define uint unsigned int#define data_8 P0sbit BUSY = P1^2; //打印机 BUSY 接P1.2sbit STB = P1^0; //打印机 STB 接P1.0Void print(uchar j) //打印子程序{ uchar i;while(BUSY){}; //BUSY=1,打印机忙,等待BUSY 为0 再发数data_8=j;STB=0;i++;i--;STB=1; //给出数据锁存时钟BUSY=1;}Void main(Void){BUSY = 1; //忙信号置高STB = 1; //选通信号置高print(0x1b); //打印机初始化命令print(0x38);print(0x04);for(;;){print(0xd0); //发送汉字内码“新荣达”print(0xc2);print(0xc8);print(0xd9);print(0xb4);print(0xef);print(0x0d); //换行}}

    标签: 微型打印机 打印

    上传时间: 2013-11-12

    上传用户:lwq11

  • 微型打印机的C语言源程序

    微型打印机的C语言源程序:微型打印机的C51源程序#define uchar unsigned char#define uint unsigned int#include <reg52.h>#include <stdio.h>#include <absacc.h>#include <math.h>#include <string.h>#include <ctype.h>#include <stdlib.h>#define PIN XBYTE[0x8000]#define POUT XBYTE[0x9000]sbit PRINTSTB =P1^6;sbit DOG=P1^7;bdata char pin&#118alue;sbit PRINTBUSY=pin&#118alue^7;sbit PRINTSEL =pin&#118alue^6;sbit PRINTERR =pin&#118alue^5;sbit PRINTACK =pin&#118alue^4;  Void PrintString(uchar *String1,uchar *String2);Void initprint(Void);Void print(uchar a);  Void initprint(Void) //打印机初始化子程序 {  pin&#118alue=PIN;  if((PRINTSEL==1)&&(PRINTERR==1))  {    print(0x1b); print(0x40); print(0x1b); print(0x38); print(0x4);  }}Void print(uchar a) //打印字符a{  pin&#118alue=PIN;  if((PRINTSEL==0)||(PRINTERR==0)) return;  for(;;) {    DOG=~DOG;    pin&#118alue=PIN;    if(PRINTBUSY==0) break;  }  DOG=~DOG;  POUT=a;  PRINTSTB=1;  PRINTSTB=1;  PRINTSTB=1;  PRINTSTB=1;  PRINTSTB=0;  PRINTSTB=0;  PRINTSTB=0;  PRINTSTB=0;  PRINTSTB=1;}Void PrintString(uchar *String) //打印字符串后回车{  uchar CH;  for (;;) {   DOG=~DOG;   CH=*String;   if (CH==0) { print(0x0d); break; }   print(CH);   String++;  }  initprint();}

    标签: 微型打印机 C语言 源程序

    上传时间: 2013-10-17

    上传用户:hasan2015

  • LC7461遥控解码子程序源代码

    //遥控解码子程序,LC7461,用户码为11C//external interrupt0Void isr_4(){  unsigned char r_count;//定义解码的个数 unsigned long use_data=0;//定义16位的用户码,只用到13位 unsigned long use_code=0;//定义16位的用户反码,只用到13位 unsigned long data=0;//定义16位数据码,包括8位数据码和反码 unsigned char data_h=0;//数据反码 unsigned char data_l=0;//数据码 _clrwdt();// _delay(7000);//7461解码,延时7000// _delay(7000);//7461解码,延时7000//_delay(7000);//7461解码,延时7000 if(remote==1)  goto error; while(remote==0);//wait to high //_delay(9744);count_delay=0; while(count_delay<143); if(remote==1)  goto error;     /////用户码解码use_data//////////add//////////////////////////     for(r_count=13;r_count>0;r_count--)  {  while(remote==0);//wait to high  count_delay=0;     while(count_delay<24);//_delay(1680);  _c=remote;  if(_c==1)   {   _lrrc(&use_data);   count_delay=0;         while(count_delay<32);//_delay(2200);//wait to low   }  else   _lrrc(&use_data);  }  _nop(); //if(remote==1)  //_delay(1680);//wait to low while(remote==1);//wait to low     _nop();     ////////用户码解码finish/////////add/////////add////////     /////用户码反码解码use_code//////////add//////////////////////////     for(r_count=13;r_count>0;r_count--)  {  while(remote==0);//wait to high  count_delay=0;         while(count_delay<24);//_delay(1680);  _c=remote;  if(_c==1)   {   _lrrc(&use_code);   count_delay=0;         while(count_delay<32);//_delay(2200);//wait to low   }  else   _lrrc(&use_code);  } _nop(); //if(remote==1) // _delay(1680);//wait to low while(remote==1);//wait to low     _nop();     ////////用户码反码解码finish/////////add/////////add////////     ////数据码解码开始////data_l为用户码,data_h为数据码反码//////////// for(r_count=16;r_count>0;r_count--)  {  while(remote==0);//wait to high  count_delay=0;         while(count_delay<24);//_delay(1680);  _c=remote;  if(_c==1)   {   _lrrc(&data);   count_delay=0;         while(count_delay<32);//_delay(2200);//wait to low   }  else   _lrrc(&data);  } ////数据码解码结束//////////////////////////////////////////////// data_l=data; data_h=data>>8; ///用户码////// use_data>>=3; use_code>>=3; use_code=~use_code; //////// ////如果用户码等与0x11c并且数据码和数据反码都校验一致,解码成功 //if((~data_h==data_l)&&use_data==0x11c)//使用用户码 //跳过用户码 if(~data_h==data_l)//如果数据码和数据反码(取反后)相等,解码正确  {  _nop();  r_data=data_l;//r_data为解出的最终数据码  } //否则解码不成功 _nop(); _nop();error:  //r_data=nocode; _nop();    _nop(); _nop();}

    标签: 7461 LC 遥控 解码

    上传时间: 2014-03-27

    上传用户:shenlan