Design of driver based on 51 single chip microcomputer (C51)

Publisher:温柔心情Latest update time:2017-12-30 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

*——————————————————————
〖Description〗SPI bus driver includes the standard mode of ordinary package and the standard mode of special package,
and the default crystal oscillator is 11.0592MHz.
〖File〗93CXX.C ﹫2003/5/12
〖Version〗V3.00A Build 0803
———————————————————————*/
/*General 93c06-93c86 series instructions
93c06=93c46 93c56=93c66 93c76=93c86
DIPx can be defined by yourself*/
#include "reg51.h"
#include "intrins.h"
/*-----------------------------------------------------
SPI93cXX series timing function call (ordinary package)
Calling method: self-define ﹫2001/05/12
Function description: Private function, encapsulates various interface definitions
-----------------------------------------------------*/
#define di_93 dip3
#define sk_93 dip2
#define cs_93 dip1
#define do_93 dip4
#define gnd_93 dip5
#define org_93 dip6
sbit cs_93=P1^0;
sbit sk_93=P1^1;
sbit di_93=P1^2;
sbit do_93=P1^3;
sbit org_93=P0^4;
/*-----------------------------------------------------
SPI93cXX series timing function call (normal package)
Calling method: void high46(void) ---high 8-bit function call
void low46(void) ---low 8-bit function call ﹫2001/05/12
Function description: Private function, SPI dedicated 93c46 normal package driver program
-----------------------------------------------------*/
void high46(void)
{
di_93=1;
sk_93=1; _nop_();
sk_93=0;_nop_();
}
void low46(void)
{
di_93=0;
sk_93=1;_nop_();
sk_93=0;_nop_();
}
void wd46(unsigned char dd)
{
unsigned char i;
for (i=0;i<8;i++)
{
if (dd>=0x80) high46();
else low46();
dd=dd<<1;
}
}
unsigned char rd46(void)
{
unsigned char i,dd;
do_93=1;
for (i=0;i<8;i++)
{
dd<<=1;
sk_93=1;_nop_();
sk_93=0;_nop_();
if (do_93) dd|=1;
}
return(dd);
}
/*-----------------------------------------------------
SPI93cXX series timing function call (special package)
Calling method: self-defined﹫2001/05/12
Function description: private function, special package interface definition
-----------------------------------------------------*/
#define di_93a dip5
#define sk_93a dip4
#define cs_93a dip3
#define do_93a dip6
#define gnd_93a dip7
#define v CC _93a out_vcc(2)
sbit cs_93a=P1^0;
sbit sk_93a=P1^1;
sbit di_93a=P1^2;
sbit do_93a=P1^3;
/*-----------------------------------------------------
SPI93cXX series timing function call (special package)
Calling method: void high46a(void) --- High 8-bit function call
void low46a(void) --- Low 8-bit function call ﹫2001/05/12
Function description: Private function, SPI dedicated 93c46 special package driver program
-----------------------------------------------------*/
void high46a(void)
{
di_93a=1;
sk_93a=1;_nop_();
sk_93a=0;_nop_();
}
void low46a(void)
{
di_93a=0;
sk_93a=1;_nop_();
sk_93a=0;
_nop_ ();
}
void wd46a(unsigned char dd)
{
unsigned char i;
for (i=0;i<8;i++)
{
if (dd>=0x80) high46a();
else low46a();
dd=dd<< 1;
}
}
unsigned char rd46a(void)
{
unsigned char i,dd;
do_93a=1;
for (i=0;i<8;i++)
{
dd<<=1;
sk_93a=1;_nop_();
sk_93a=0;_nop_();
if (do_93a) dd|=1;
}
return(dd);
}
/*------------------------ -----------------------------
SPI93c46 series function call (example)
Calling method: bit write93c56_word(unsigned int address,unsigned int dat) ﹫2001/05/12
Function description: Private function, SPI only
------------------------------------ -----------------*/
void ewen46(void)
{
_nop_();
cs_93=1;
high46();
wd46(0x30);
cs_93=0;
}
unsigned int read93c46_word (unsigned char address)
{
unsigned int dat;
unsigned char dat0,dat1;
gnd_93a=0;
gnd_93=0;
cs_93=sk_93=0;
org_93=1;
cs_93=1;_nop_();
address=address>>1;
address=address|0x80;
address=address|0x80;
high46();
wd46(address);
dat1=rd46();
dat0=rd46( );
cs_93=0;
dat=dat1*256+dat0;
return(dat);
}
bit write93c46_word(unsigned char address,unsigned int dat)
{
unsigned char e,temp=address;
e=0;
while (e<3)
{
gnd_93a=0;
gnd_93=0;
cs_93=sk_93=0;
org_93=1;
cs_93=1;
ewen46();
_nop_();
cs_93=1;
_nop_();
high46();
address|=0x80;
address>>=1;//??
address|=0x40;
wd46(address);
wd46(dat/256);
wd46(dat%256);
cs_93=0;
_nop_();
cs_93=1 ;
time=0;do_93=1;
while (1)
{
if (do_93==1) break;
if (time>20) break;
}
cs_93=0;
if (read93c46_word(temp)==dat)
{
return(0 );
}
e++;
}
return(1);
}
/*------------------------------------ -----------------
SPI93c57 series function call (example)
Calling method: bit write93c57_word(unsigned int address,unsigned int dat) ﹫2001/05/12
Function description: Private function, SPI dedicated
-----------------------------------------------------*/
void ewen57(void)
{
_nop_();
cs_93=1;
dip7=0;
high46();
low46();
wd46(0x60);
cs_93=0;
}
unsigned int read93c57_word(unsigned int address)
{
unsigned int dat;
unsigned char dat0,dat1;
gnd_93=0;
cs_93=sk_93=0;
org_93=1;
cs_93=1;
address=address>>1;
high46();
high46();
wd46(address);
dat1=rd46();
dat0=rd46();
cs_93=0;
dat=dat1*256+dat0;
return(dat);
}
bit write93c57_word(unsigned int address,unsigned int dat)
{
unsigned char e;
unsigned int temp=address;
e=0;
while (e<3)
{
gnd_93=0;
cs_93=sk_93=0;
org_93= 1;
cs_93=1;
ewen57();
cs_93=1;
_nop_();
high46();
low46();
address>>=1;
address|=0x80;
wd46(address);
wd46(dat/256);
wd46(dat%256); cs_93=
0; _nop_
() ; 3=1; while (1) { if (do_93==1) break; if (time>20) break; } cs_93=0; if (read93c57_word(temp)==dat) { return(0); } e++; } return(1); } /*----------------------------------------------------- SPI93c56 series function call (example) Calling method: bit write93c56_word(unsigned int address,unsigned int dat) ﹫2001/05/12 Function description: Private function, SPI dedicated -----------------------------------------------------*/ void ewen56(void) { _nop_(); cs_93=1; high46(); low46(); low46(); wd46(0xc0); cs_93=0; } unsigned int read93c56_word(unsigned char address) { unsigned int dat; unsigned char dat0,dat1; gnd_93=0; cs_93=sk_93=0; org_93=1; cs_93=1; address=address>>1; high46(); high46(); low46(); wd46(address); dat1=rd46() ; dat0 = rd46() ; return (dat); } bit write93c56_word(unsigned char address,unsigned int dat) { unsigned char e; unsigned int temp=address; e=0;
























































while (e<3)
{
gnd_93=0;
cs_93=sk_93=0;
org_93=1;
cs_93=1;
ewen56();
_nop_();
cs_93=1;
_nop_();
high46();
low46();
high46 ();
address>>=1;
wd46(address);
wd46(dat/256);
wd46(dat%256);
cs_93=0;
_nop_();
cs_93=1;
TH0=0;
time=0;
do_93= 1;
while (1)
{
if (do_93==1) break;
if (time) break;
}
cs_93=0;
if (read93c56_word(temp)==dat)
{
return(0);
}
e++;
}
return(1 );
}
/*------------------------------------------------ --------
SPI93c76 and SPI93c86 series function call (example)
Calling method: bit write93c76_word (unsigned int address, unsigned int dat) ﹫2001/05/12
Function description: Private function, SPI dedicated
------------- ----------------------------------------*/
void ewen76(void)
{
_nop_( );
cs_93=1;
dip7=1;
high46();
low46();
low46();
high46();
high46();
wd46(0xff);
cs_93=0;
}
unsigned int read93c76_word(unsigned int address)
{
unsigned char dat0,dat1;
gnd_93=0;
cs_93=sk_93=0;
org_93=1;
cs_93=1;
address>>=1;
high46();
high46();
low46();
if((address&0x200)==0x200) high46();
else low46();
if ((address&0x100)==0x100) high46();
else low46();
wd46(address);
dat1=rd46();
dat0=rd46 ();
cs_93=0;
return(dat1*256|dat0);
}
bit write93c76_word(unsigned int address,unsigned int dat)
{
unsigned char e;
unsigned int temp=address;
e=0;
address>>=1;
while (e<3)
{
gnd_93=0;
cs_93=sk_93=0;
org_93=1;
cs_93=1;
ewen76();
_nop_();
cs_93=1;
high46();
low46();
high46();
if((address&0x200)==0x200) high46();
else low46();
if ((address&0x100)==0x100) high46();
else low46();
wd46(address);
wd46(dat/256 );
wd46(dat%256);
cs_93=0;_nop_();cs_93=1;
time=0;do_93=1;
while (1)
{
if (do_93==1) break;
if (time>10) break ;
}
cs_93=0;
e++;
}
return(1);
}
/*--------------------------------- -------------------
Main function call (example)
Calling method: main() ﹫2001/05/12
Function description: Private function, dedicated to SPI
-----------------------------------------------------*/
main()
{ bit b;
unsigned int i;
unsigned int j[32],k;
for(i=0;i<32;i++)
j[i]=read93c56_word(i);
for(i=0;i<32;i++)
write93c56_word(i,0x0909);
i=0;
b=write93c56_word(i,0x0909);
j[i]=read93c56_word(i);
i=1;
b=write93c56_word(i,0x1111);
j[i]=read93c56_word(i);
i=2;
b=write93c56_word(i,0x2222);
j[i]=read93c56_word(i);
}

Reference address:Design of driver based on 51 single chip microcomputer (C51)

Previous article:X25045/X5045 standard function set based on C51
Next article:51 MCU IO port simulation serial communication program design example

Recommended ReadingLatest update time:2024-11-16 15:50

Forward-looking technologies converge in cars, and technology accumulation drives intelligent driving in ALE 2024
(June 26, 2026) In recent years, the automotive field has been thriving due to the introduction of forward-looking technologies such as AI and the Internet of Vehicles, which have commercialized technologies. In particular, the market penetration of electric vehicles has increased year by year. Car manufacturers,
[Automotive Electronics]
Forward-looking technologies converge in cars, and technology accumulation drives intelligent driving in ALE 2024
Tiny210 button layer separation (bus-driver-device model)
led_dev.c driver source code: #include "linux/module.h" #include "linux/version.h" #include "linux/init.h" #include "linux/kernel.h" #include "linux/types.h" #include "linux/interrupt.h" #include "linux/list.h" #include "linux/timer.h" #include "linux/init.h" #include "linux/serial_core.h" #include "linux/platform_dev
[Microcontroller]
c51: Serial port interrupt mode, sending and receiving character strings
/* Programming features: 1. Parameters f=12MHZ, baud=1200 2. Serial port interrupt mode: The sent string is stored in the character array tran_buf , and the received string is stored in the character array rec_buf . 2. The sending string is controlled by a 16-bit keyboard. The keyboard is scanned every 10ms by T
[Microcontroller]
Auto parts supplier Magna showcases e4 electric drive system, which can increase pure electric range by 120km
Magna, one of the largest automotive parts suppliers, recently showed a demonstration car equipped with its latest technology e4 electric drive system at a winter test drive event in northern Sweden. The e4 electric drive system is based on the Jaguar I-PACE, but the purpose of this car is to demonstrate Magna's scala
[Automotive Electronics]
Auto parts supplier Magna showcases e4 electric drive system, which can increase pure electric range by 120km
Design of a DC motor H-bridge drive circuit
This circuit uses NMOS field effect tube as power output device, designs and implements high power DC motor H bridge drive circuit, and performs closed loop control on 25D60-24A DC motor with rated voltage of 24V and rated current of 3.8A. The circuit has strong anti-interference ability and strong applicability in th
[Power Management]
Design of a DC motor H-bridge drive circuit
Motor drive and interactive control test based on MDA810 motor drive analyzer
Debugging motor drive control systems often requires viewing control signals and power waveforms that occur simultaneously in dynamic events to understand the cause-effect relationship, visualize the dynamic power behavior over time, and the correlation with control signals. Traditional power analyzers only provide st
[Test Measurement]
Motor drive and interactive control test based on MDA810 motor drive analyzer
Introduction to the IO port of C51 microcontroller (Part 2)
In the previous article, we briefly introduced the IO of C51. Now let’s briefly understand the structure of C51 IO. Here we learn about the more common IO modes of microcontrollers, which are quasi-bidirectional, open-drain output and push-pull output. (I should mention here that the STC88C52RC we use does not have
[Microcontroller]
Introduction to the IO port of C51 microcontroller (Part 2)
Interpretation: How does LED driver chip affect the life of LED lamps
In recent years, LED, as a new energy-saving light source, has won high investment enthusiasm and great attention in the world and China, and has penetrated from outdoor to indoor lighting application markets. China has also seen the emergence of tens of thousands of LED lighting companies of all sizes. The main reason
[Power Management]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号