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(); /////////////////////////停止條件; }
上傳時間: 2013-11-18
上傳用戶:墻角有棵樹
16 16點陣顯示漢字原理及顯示程序 #include "config.h" #define DOTLED_LINE_PORT PORTB #define DOTLED_LINE_DDR DDRB #define DOTLED_LINE_PIN PINB #define DOTLED_LINE_SCKT PB1 #define DOTLED_LINE_SCKH PB5 #define DOTLED_LINE_SDA PB3 #define DOTLED_ROW_PORT PORTC #define DOTLED_ROW_DDR DDRC #define DOTLED_ROW_PIN PINC #define DOTLED_ROW_A0 PC0 #define DOTLED_ROW_A1 PC1 #define DOTLED_ROW_A2 PC2 #define DOTLED_ROW_A3 PC3 #define DOTLED_ROW_E PC4 uint8 font[] = { /*-- 調入了一幅圖像:這是您新建的圖像 --*/ /*-- 寬度x高度=16x16 --*/ 0X00,0X00,0X00,0X00,0x08,0x38,0x18,0x44,0x08,0x44,0x08,0x04,0x08,0x08,0x08,0x10, 0x08,0x20,0x08,0x40,0x08,0x40,0x08,0x40,0x3E,0x7C,0X00,0X00,0X00,0X00,0X00,0X00 }; static void TransmitByte(uint8 byte); static void SelectRow(uint8 row); static void FlipLatchLine(void); static void TransmitByte(uint8 byte) { uint8 i; for(i = 0 ; i < 8 ; i ++) { if(byte & (1 << i)) { DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SDA); } else { DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SDA); } //__delay_cycles(100); DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SCKH); //__delay_cycles(100); DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SCKH); //__delay_cycles(100); } } static void SelectRow(uint8 row) { //row -= 1; row |= DOTLED_ROW_PIN & 0xe0; DOTLED_ROW_PORT = row; } static void FlipLatchLine(void) { DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SCKT); DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SCKT); } void InitDotLedPort(void) { DOTLED_LINE_PORT &= ~(_BV(DOTLED_LINE_SCKT) | _BV(DOTLED_LINE_SCKH)); DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SDA); DOTLED_LINE_DDR |= _BV(DOTLED_LINE_SCKT) | _BV(DOTLED_LINE_SCKH) | _BV(DOTLED_LINE_SDA); DOTLED_ROW_PORT |= 0x1f; DOTLED_ROW_PORT &= 0xf0; DOTLED_ROW_DDR |= 0x1f; } void EnableRow(boolean IsEnable) { if(IsEnable) { DOTLED_ROW_PORT &= ~_BV(DOTLED_ROW_E); } else { DOTLED_ROW_PORT |= _BV(DOTLED_ROW_E); } } void PrintDotLed(uint8 * buffer) { uint8 i , tmp; for(i = 0 ; i < 16 ; i ++) { tmp = *buffer ++; TransmitByte(~tmp); tmp = *buffer ++; TransmitByte(~tmp); SelectRow(i); FlipLatchLine(); } } void main(void) { InitDotLedPort(); EnableRow(TRUE); while(1) { PrintDotLed(font); __delay_cycles(5000); } } //---------------------------------------------------- config.h文件 #ifndef _CONFIG_H #define _CONFIG_H //#define GCCAVR #define CPU_CYCLES 7372800L #ifndef GCCAVR #define _BV(bit) (1 << (bit)) #endif #define MSB 0x80 #define LSB 0x01 #define FALSE 0 #define TRUE 1 typedef unsigned char uint8; typedef unsigned int uint16; typedef unsigned long uint32; typedef unsigned char boolean; #include <ioavr.h> #include <inavr.h> #include "dotled.h" #endif //-----
上傳時間: 2013-11-18
上傳用戶:mnacyf
飛思卡爾智能車的舵機測試程序 #include <hidef.h> /* common defines and macros */#include <MC9S12XS128.h> /* derivative information */#pragma LINK_INFO DERIVATIVE "mc9s12xs128" void SetBusCLK_16M(void) { CLKSEL=0X00; PLLCTL_PLLON=1; //鎖相環電路允許位 SYNR=0X00 | 0x01; //SYNR=1 REFDV=0x80 | 0x01; POSTDIV=0X00; _asm(nop); _asm(nop); while(!(CRGFLG_LOCK==1)); CLKSEL_PLLSEL =1; } void PWM_01(void) { //舵機初始化 PWMCTL_CON01=1; //0和1聯合成16位PWM; PWMCAE_CAE1=0; //選擇輸出模式為左對齊輸出模式 PWMCNT01 = 0; //計數器清零; PWMPOL_PPOL1=1; //先輸出高電平,計數到DTY時,反轉電平 PWMPRCLK = 0X40; //clockA 不分頻,clockA=busclock=16MHz;CLK B 16分頻:1Mhz PWMSCLA = 0x08; //對clock SA 16分頻,pwm clock=clockA/16=1MHz; PWMCLK_PCLK1 = 1; //選擇clock SA做時鐘源 PWMPER01 = 20000; //周期20ms; 50Hz; PWMDTY01 = 1500; //高電平時間為1.5ms; PWME_PWME1 = 1;
上傳時間: 2013-11-04
上傳用戶:狗日的日子
c8051f020 實時時鐘模塊程序 內含IIC模塊程序/********************** SYSTEM CLOCK 8M********************************/ extern unsigned char xdata currenttime[16]={0} extern unsigned char xdata settime[16]={ 0X00, // control regesiter 1 0X00, // control regesiter 2 0x01, //current second 0x19, //current minute 0x20, //current hour 0x29, //current data 0x04, //current week 0x07, //current month 0x05, //current year 0X00, // alarm value reset 0X00, // alarm value reset 0X00, // alarm value reset 0X00, // alarm value reset 0X00, // clk out disable 0X00, // close timer 0X00, } /*********************************************************************/ extern void Current_Time ( void ) extern void Set_Time ( void )
標簽: c8051f020 SYSTEM CLOCK IIC
上傳時間: 2015-06-30
上傳用戶:edisonfather
C語言庫函數速查[CHM文檔]是一個很好的C語言函數查詢器.屬于CHM文檔. iscntrl 原型:extern int iscntrl(int c) 用法:#include <ctype.h> 功能:判斷字符c是否為控制字符 說明:當c在0X00-0x1F之間或等于0x7F(DEL)時,返回非零值,否則返回零。
上傳時間: 2015-08-15
上傳用戶:lht618
DA 輸出地址0x20400000 由于DAC0832要求輸出鎖存保持1uS左右 但CPU在讀寫(對應nGCS4)寫信號最大只能到100ns左右 所以外面加了一個地址鎖存74573,573鎖存下降沿有效(現在是上升沿有效,也可用) 現在電阻不變的情況下,輸出0X00,DA輸出0V,輸出0xff,DA輸出1.7V左右
標簽: 0x20400000 74573 nGCS4 0832
上傳時間: 2014-01-04
上傳用戶:gaojiao1999
CRC16算法的Java實現,使用方法如下: CRC16 crc16 = new CRC16() byte[] b = new byte[] { // (byte) 0xF0,(byte)0xF0,(byte)0xF0,(byte)0x72 (byte) 0x2C, (byte) 0X00, (byte) 0xFF, (byte) 0xFE, (byte) 0xFE, (byte) 0x04, (byte) 0X00, (byte) 0X00, (byte) 0X00, (byte) 0X00 } for (int k = 0 k < b.length k++) { crc16.update(b[k]) } System.out.println(Integer.toHexString(crc16.getValue())) System.out.println(Integer.toHexString(b.length))
上傳時間: 2014-12-20
上傳用戶:ve3344
51單片連tcs230的源程序,絕對原創,可以記憶顏色。 #define uchar unsigned char #include <reg52.h> #include<math.h> sbit S0=P1^7 sbit S1=P1^0 //端口定義 sbit S2=P1^1 sbit S3=P1^2 sbit OE=P1^3 sbit OUT=P3^4 //頻率從TO口輸入 sbit key0=P1^5 sbit LED=P1^6 sbit a=P3^0 sbit b=P3^1 uchar color //1:blue 2:green 3:red uchar T[4] //color timer uchar TH[4] uchar TL[4] uchar bizhi[4] void time1() interrupt 3 { TH[color]=TH0 TL[color]=TL0 T[color]=(TH[color]*0xff+TL[color]) TR0=0 //關定時器 TR1=0 TH1=0xB1 TL1=0xE0 //歸0 TH0=0X00 TL0=0X00 //歸0 }
上傳時間: 2016-11-26
上傳用戶:秦莞爾w
CAN1.c and CAN2.c are a simple example of configuring a CAN network to transmit and receive data on a CAN network, and how to move information to and from CAN RAM message objects. Each C8051F040-TB CAN node is configured to send a message when it s P3.7 button is depressed/released, with a 0x11 to indicate the button is pushed, and 0X00 when released. Each node also has a message object configured to receive messages. The C8051 tests the received data and will turn on/off the target board s LED. When one target is loaded with CAN2.c and the other is loaded with CAN1.c, one target board s push-button will control the other target board s LED, establishing a simple control link via the CAN bus and can be observed directly on the target boards.
標簽: CAN configuring and transmit
上傳時間: 2013-12-11
上傳用戶:weiwolkt
VB遙控播放器紅外遙控解碼 #include <regX52.h> #define c(x) (x*110592/120000) sbit Ir_Pin=P3^2 sbit beep=P2^1 //sbit RELAY=P2^0 #define INBUF_LEN 4 //數據長度 unsigned char inbuf1[INBUF_LEN]={ 0 , 0 , 0 , 0 } //發送緩沖區 unsigned char inbuf2[50] //接收緩沖區 unsigned char count3 void init_serialcomm( void ) { SCON = 0x50 //SCON: serail mode 1, 8-bit UART, enable ucvr T2CON=0x30 TH2=0X00 TL2=0X00 RCAP2H=0xFF RCAP2L=0xDC TR2=1 } //向串口發送一個字符 void send_char_com( unsigned char ch) { SBUF=ch while (TI== 0 ) TI= 0
標簽: include 110592 120000 define
上傳時間: 2013-12-21
上傳用戶:yph853211