www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀] //ICC-AVR applICation// Target : M8515// Crystal: 4.0000MHz#include #include void port_init(void){PORTA = 0x00;DDRA = 0x03;PORTB = 0x00;DDRB = 0x70;PORTC = 0x00;DDRC = 0x70;PORTD = 0xff;D

//ICC-AVR applICation
// Target : M8515
// Crystal: 4.0000MHz

#include
#include

void port_init(void)
{
PORTA = 0x00;
DDRA = 0x03;

PORTB = 0x00;
DDRB = 0x70;
PORTC = 0x00;
DDRC = 0x70;
PORTD = 0xff;
DDRD = 0x00;
PORTE = 0x00;
DDRE = 0x00;
}



//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //dISAble all interrupts
port_init();

MCUCR = 0x00;
EMCUCR = 0x00;
GICR = 0x40;
TIMSK = 0x00;
SEI(); //re-enable interrupts
//all peripherals are now initialized
}


#define uchar unsigned char
#define uint unsigned int

#defineLED_str_off PORTC&=~(1<#define led_clk_off PORTC&=~(1<#define led_d_off PORTC&=~(1<#define led_str_on PORTC|=(1<#define led_clk_on PORTC|=(1<#define led_d_on PORTC|=(1<

#define OP_READ 0xa1 // 器件地址以及讀取操作
#define OP_WRITE 0xa0 // 器件地址以及寫入操作
#define MAX_ADDR 0x7f // AT24C02最大地址

unsigned char dis_code[] = {0x81,0xB7,0xC2,0x92,0xB4,0x98,0x88,0xB3,0x80,0x90};
unsigned char a[]={90,11,12,13,14,15,22,7,8,9};
uchar led_buffer[4]={0,3};

#define SDA PA1
#define SCL PA0

#define SDA_on PORTA|=(1<#define SDA_off PORTA&=~(1<#define SCL_on PORTA|=(1<#define SCL_off PORTA&=~(1<

//void start();
//void stop();
//unsigned char shin();
//unsigned char shout(unsigned char write_data);
unsigned char read_random(unsigned char random_addr);
void write_byte( unsigned char addr, unsigned char write_data);
void fill_byte(unsigned char fill_data);
void delayms(unsigned char ms);
void update_display_dp(void);
void jisuan(uchar b_data );

unsigned char ndatatodisplay,gewei,shiwei;


main(void)
{
uchar i;
port_init();
SDA_on;
SCL_on;
fill_byte(0xff); // 全部填充0xff

for(i = 0 ; i < 10; i++) //寫入顯示代碼到AT24Cxx
{
write_byte(i, a);
}
init_devices();
while(1);
}

#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
uchar i;
jisuan((read_random(i)));
ndatatodisplay =( shiwei*10+gewei); // 循環(huán)讀取24Cxx內(nèi)容,并輸出到P0口
i++;
if(i>9)i=0; // 循環(huán)讀取范圍為0x00~0x07
delayms(250);
update_display_dp();
}
void _nop_()
{
}
void update_display_dp(void)
{
uchar bit_count=0;
uchar byte_counter=0;
uchar i=0;
led_buffer[3]=ndatatodisplay/1000;
led_buffer[2]=(ndatatodisplay%1000)/100;
led_buffer[1]=(ndatatodisplay%100)/10;
led_buffer[0]=ndatatodisplay%10;
led_str_off;
led_clk_off;
for(byte_counter=0;byte_counter<4;byte_counter++)
{
bit_count=8;
i=dis_code[led_buffer][byte_counter]];

while(bit_count>0)
{
if((i&0x01)==0)
{
led_d_off;
}
else
{
led_d_on;
}
i=(i>>1);


led_clk_on;

led_clk_off;

bit_count--;

}

}

led_str_on;


}

void jisuan(uchar b_data )
{

uchar e,d;
e=b_data;
d=e;
e=e&0x0f;
d=d>>4;
gewei=(e&0x01)+((e>>1)&0x01)*2+((e>>2)&0x01)*4+((e>>3)&0x01)*8;
shiwei=(d&0x01)+((d>>1)&0x01)*2+((d>>2)&0x01)*4+((d>>3)&0x01)*8;

}


void start()
// 開始位
{
SDA_on;
SCL_on;
_nop_();
_nop_();
SDA_off;
_nop_();
_nop_();
_nop_();
_nop_();
SCL_off;
}

void stop()
// 停止位
{
SDA_off;
_nop_();
_nop_();
SCL_on;
_nop_();
_nop_();
_nop_();
_nop_();
SDA_on;
}

unsigned char shin()
// 從AT24Cxx移入數(shù)據(jù)到MCU
{
unsigned char i,read_data;

for(i = 0; i < 8; i++)
{
SCL_on;
DDRA&=0xfd;
read_data <<= 1;
read_data |= (PINA&0X02);
SCL_off;
DDRA&=0xfd;
}
return(read_data);
}
uchar shout(unsigned char write_data)
// 從MCU移出數(shù)據(jù)到AT24Cxx
{
unsigned char i;
uchar ack_bit;

for(i = 0; i < 8; i++) // 循環(huán)移入8個位
{
if(write_data & 0x80)
{
SDA_on;
DDRA=0XFF;
_nop_();
}
else
{
SDA_off;
DDRA=0XFF;
_nop_();
}

SCL_on;
DDRA=0XFF;
_nop_();
_nop_();
SCL_off;
DDRA=0XFF;
write_data <<= 1;
}
SDA_on;
DDRA=0XFF; // 讀取應(yīng)答
_nop_();
_nop_();
SCL_on;
DDRA=0XFF;
_nop_();
_nop_();
_nop_();
_nop_();
ack_bit = PINA&0X02;
SCL_off;
DDRA=0XFF;
return ack_bit; // 返回AT24Cxx應(yīng)答位
}

void write_byte(unsigned char addr, unsigned char write_data)
// 在指定地址addr處寫入數(shù)據(jù)write_data
{
start();
shout(OP_WRITE);
shout(addr);
shout(write_data);
stop();
delayms(10); // 寫入周期
}

void fill_byte(unsigned char fill_data)
// 填充數(shù)據(jù)fill_data到EEPROM內(nèi)
{
unsigned char i;
for(i = 0; i < MAX_ADDR; i++)
{
write_byte(i, fill_data);
}

}

unsigned char read_current()
// 在當(dāng)前地址讀取
{
unsigned char read_data;

start();
shout(OP_READ);

read_data = shin();
stop();
return read_data;
}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

在這篇文章中,小編將對PLC的相關(guān)內(nèi)容和情況加以介紹以幫助大家增進(jìn)對它的了解程度,和小編一起來閱讀以下內(nèi)容吧。

關(guān)鍵字: PLC 模塊化 程序

一直以來,步進(jìn)電機(jī)都是大家的關(guān)注焦點(diǎn)之一。因此針對大家的興趣點(diǎn)所在,小編將為大家?guī)聿竭M(jìn)電機(jī)的相關(guān)介紹,詳細(xì)內(nèi)容請看下文。

關(guān)鍵字: 電機(jī) 步進(jìn)電機(jī)

本文中,小編將對步進(jìn)電機(jī)予以介紹,如果你想對它的詳細(xì)情況有所認(rèn)識,或者想要增進(jìn)對它的了解程度,不妨請看以下內(nèi)容哦。

關(guān)鍵字: 電機(jī) 步進(jìn)電機(jī)

在這篇文章中,小編將為大家?guī)聿竭M(jìn)電機(jī)的相關(guān)報道。如果你對本文即將要講解的內(nèi)容存在一定興趣,不妨繼續(xù)往下閱讀哦。

關(guān)鍵字: 電機(jī) 步進(jìn)電機(jī)

今天,小編將在這篇文章中為大家?guī)聿竭M(jìn)電機(jī)的有關(guān)報道,通過閱讀這篇文章,大家可以對它具備清晰的認(rèn)識,主要內(nèi)容如下。

關(guān)鍵字: 電機(jī) 步進(jìn)電機(jī) 相電流

步進(jìn)電機(jī)將是下述內(nèi)容的主要介紹對象,通過這篇文章,小編希望大家可以對它的相關(guān)情況以及信息有所認(rèn)識和了解,詳細(xì)內(nèi)容如下。

關(guān)鍵字: 電機(jī) 步進(jìn)電機(jī)

在這篇文章中,小編將對步進(jìn)電機(jī)的相關(guān)內(nèi)容和情況加以介紹以幫助大家增進(jìn)對它的了解程度,和小編一起來閱讀以下內(nèi)容吧。

關(guān)鍵字: 電機(jī) 步進(jìn)電機(jī)

在下述的內(nèi)容中,小編將會對步進(jìn)電機(jī)的相關(guān)消息予以報道,如果步進(jìn)電機(jī)是您想要了解的焦點(diǎn)之一,不妨和小編共同閱讀這篇文章哦。

關(guān)鍵字: 電機(jī) 步進(jìn)電機(jī)

本文中,小編將對電機(jī)予以介紹,如果你想對它的詳細(xì)情況有所認(rèn)識,或者想要增進(jìn)對它的了解程度,不妨請看以下內(nèi)容哦。

關(guān)鍵字: 電機(jī) 步進(jìn)電機(jī)

完成這個項目有幾個原因。首先,它通過動手模型幫助學(xué)生了解太陽系。其次,這是練習(xí)使用Arduino和步進(jìn)電機(jī)的好方法。最后,它通過讓學(xué)習(xí)變得有趣和富有創(chuàng)造性來鼓勵人們對STEM的興趣。

關(guān)鍵字: Arduino 步進(jìn)電機(jī) STEM
關(guān)閉