During development, the ATmega8 peripheral SPI bus is used:
if((r_buf[0]==0xff)&&(r_buf[5]==0xaa))
{
r_full=1;
if(r_full)
{
r_full=0;
if(r_data[1]!=99)return;
switch(r_data[2])
{
case 3:
case 0x31:
if((r_data[4]>16)||(r_data[3]>16))return;
if(r_data[3]==0)return;
else if(r_data[4]==0)
{
for(i=0;i<16;i++)
{
tmp_ddc[i]=r_data[3];
}
}
else
{
tmp_ddc[r_data[4]-1]=r_data[3];
}
break;
default:
break;
}
}
DDRB.4=1;
DDRB.2=0;
PORTB.2=1;
DDRB.3=0;
DDRB.5=0;
SPCR=0XC0;
DDRB.4=0;
DDRB.2=1;
DDRB.3=1;
DDRB.5=1;
SPCR=0x52;
#asm("cli")
for(i=0;i<2;i++)
{
SPDR=video_new[i];
#asm("wdr")
while((SPSR&0X80)!=0X80);
}
delay_ms(10);
PORTB.2=1;
#asm("sei")
spi_init_s();
Keywords:ATmega8
Reference address:ATmega8---SPI bus control
Before sending data, it is in slave mode and in receiving state. When sending, it needs to enter master mode, and then enter slave mode after completing the sending.
The following are the operation functions:
interrupt [SPI_STC] void spi_interrupt(void)
{
//uchar tmp;
uchar i,b;
//tmp=SPSR;
b=SPDR;
r_buf[0]=r_buf[1];
r_buf[1]=r_buf[2];
r_buf[2]=r_buf[3];
r_buf[3]=r_buf[4];
r_buf[4]=r_buf[5];
r_buf[5]=b;
r_data[0]=r_buf[0];
r_data[1]=r_buf[1];
r_data[2]=r_buf[2];
r_data[3]=r_buf[3];
r_data[4]=r_buf[4];
r_data[5]=r_buf[5];
}
}
//------------------------------------------------ -
void spi_init_s() //Before there is any communication, it is in slave mode
{
}
void spi_init_m()
{
SPSR=0X01;
}
//-------------------------------------
void send_spi()
{
uchar i;
while(PINB.2==0){;}
spi_init_m();
PORTB.2=0;
delay_ms(1);
}
Previous article:AVR microcontroller realizes 232 to CAN conversion
Next article:Serial communication between different external crystals of ATmega162
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
Guess you like
- [15th Anniversary] Points Exchange - The last round of chip currency exchange, chip points are officially launched!
- My EEWorld 2018 year-end summary @ [chat, laugh, make noise]
- How to use a funnel amplifier to amplify current measurements?
- Share the open source information of the creative Coke power bank I collected, including schematics, PCB, and code
- Real-time control technologies meet the demands of real-time industrial communications – Part 3
- Share a STMF105RBT6 and 103RCT6_keil_C++ source program
- MSP430 MCU Example 3 - Colored Light Control
- EEWORLD University-What is an isolated gate driver?
- Burning image and mounting USB disk with busybox file system failed
- Switching Circuit