音影先锋亚洲天堂网|电影世界尽头的爱完整版播放|国产 熟女 91|高清无码免费观看欧美日韩|韩国一区二区三区黄色录像|美女亚洲加勒比在线|亚洲综合网 开心五月|7x成人在线入口|成人网站免费日韩毛片区|国产黄片?一级?二级?三级

登錄 免費(fèi)注冊(cè) 首頁(yè) | 行業(yè)黑名單 | 幫助
維庫(kù)電子市場(chǎng)網(wǎng)
技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測(cè)控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng)
驅(qū)動(dòng)編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機(jī) | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計(jì) | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe

這個(gè)程序是怎么會(huì)事呀?那位高手幫我看看!

作者:soosan 欄目:單片機(jī)
這個(gè)程序是怎么會(huì)事呀?那位高手幫我看看!
初學(xué)AVR,看別人的程序有疑問(wèn)請(qǐng)教:下面這些程序是在那個(gè)編譯器下寫的?怎么不改變所實(shí)現(xiàn)的功能移植到ICCAVR或者GCC上呀?
#include "iom8.h"
#include "ina90.h"
#include "macros.h"

#define LED_toggle       PORTB ^= 0x02
#define LED_on        PORTB &= ~0x02
#define LED_off        PORTB |= 0x02
#define RD_low        PORTB &= ~0x10
#define RD_high        PORTB |= 0x10
#define WR_low        PORTB &= ~0x20
#define WR_high        PORTB |= 0x20

#define NORMAL_on        PORTB &= ~0x01
#define NORMAL_off        PORTB |= 0x01
#define JACK_DOWN_on    PORTC &= ~0x10
#define JACK_DOWN_off    PORTC |= 0x10     

void delay_us(CHAR val);

CHAR timer_10ms_f,timer_100ms_f,timer_1s_f;
CHAR timer_10ms,timer_100ms,timer_1s;
CHAR test_buf;
CHAR OT_left_front,OT_right_front,OT_left_rear,OT_right_rear;
CHAR toggle_count;
CHAR INP_data[4];
LONG sum;

CHAR LEFT_on_pattern[4],LEFT_off_pattern[4];
CHAR RIGHT_on_pattern[4],RIGHT_off_pattern[4];

void sys_init(void)
{
    PORTB=0xff;
    PORTC=0xff;
    PORTD=0xff;
    
    DDRB=0x3f;
    DDRC=0x10;
    DDRD=0xff;
    
    TCCR0=0x05;
    TIFR=1;
    TCNT0=255-77;
    
    TIMSK=1;
    OSCCAL=0xff;
    // WDTCR=0x1f;
}

void var_init(void)
{
    test_buf=0;
    OT_left_front=0;
    OT_right_front=0;
    OT_left_rear=0;
    OT_right_rear=0;
    
    LEFT_on_pattern[0]=0x04;
    LEFT_off_pattern[0]=0x00;
    LEFT_on_pattern[1]=0x0c;
    LEFT_off_pattern[1]=0x04;
    LEFT_on_pattern[2]=0x0d;
    LEFT_off_pattern[2]=0x0c;
    LEFT_on_pattern[3]=0x0f;
    LEFT_off_pattern[3]=0x0d;
    
    RIGHT_on_pattern[0]=0x02;
    RIGHT_off_pattern[0]=0x00;
    RIGHT_on_pattern[1]=0x03;
    RIGHT_off_pattern[1]=0x02;
    RIGHT_on_pattern[2]=0x0b;
    RIGHT_off_pattern[2]=0x03;
    RIGHT_on_pattern[3]=0x0f;
    RIGHT_off_pattern[3]=0x0b;
}
interrupt[INT0_vect] void INT0_interrupt(void)
{}

interrupt[INT1_vect] void INT1_interrupt(void)
{}

interrupt[TIMER0_OVF_vect] void TIMER0_OVF_interrupt(void)
{
    // _SEI();
    TCNT0=255-77;
    timer_10ms_f=1;
         timer_10ms++;
    if(timer_10ms>9)
    {    timer_10ms=0;
        timer_100ms++;
        timer_100ms_f=1;
        if(timer_100ms>9)
        {    timer_100ms=0;
            timer_1s++;
            timer_1s_f=1;
        }
    }    
    
}


void test_100ms(void)
{
    unsigned CHAR left_data,right_data;
    if(timer_100ms>4)
    {    LED_on;
         }    
    else
    {    LED_off;
    }

NORMAL_on;

PORTB=PORTB & 0x33;
RD_low;
delay_us(5);
INP_data[0]=PINC & 0x0f;
RD_high;

PORTB=(PORTB & 0x33)|0x04;
RD_low;
delay_us(5);
INP_data[1]=PINC & 0x0f;
RD_high;

PORTB=(PORTB & 0x33)|0x08;
RD_low;
delay_us(5);
INP_data[2]=PINC & 0x0f;
RD_high;

PORTB=(PORTB & 0x33)|0x0c;
RD_low;
delay_us(5);
INP_data[3]=PINC & 0x0f;
RD_high;

if(((INP_data[0] & 0x01)==0) && ((INP_data[1]&0x01)==0))
{    OT_left_front=0;
}

else if(((INP_data[0] & 0x01)!=0) && ((INP_data[1]&0x01)==0))
{    OT_left_front=1;
}

else if(((INP_data[0] & 0x01)!=0) && ((INP_data[1]&0x01)!=0))
{    OT_left_front=2;
}

else if(((INP_data[0] & 0x01)==0) && ((INP_data[1]&0x01)!=0))
{    OT_left_front=3;
}

//

if(((INP_data[0] & 0x02)==0) && ((INP_data[1]&0x02)==0))
{    OT_right_front=0;
}

else if(((INP_data[0] & 0x02)!=0) && ((INP_data[1]&0x02)==0))
{    OT_right_front=1;
}

else if(((INP_data[0] & 0x02)!=0) && ((INP_data[1]&0x02)!=0))
{    OT_right_front=2;
}

else if(((INP_data[0] & 0x02)==0) && ((INP_data[1]&0x02)!=0))
{    OT_right_front=3;
}

//

if(((INP_data[0] & 0x04)==0) && ((INP_data[1]&0x04)==0))
{    OT_left_rear=0;
}

else if(((INP_data[0] & 0x04)!=0) && ((INP_data[1]&0x04)==0))
{    OT_left_rear=1;
}

else if(((INP_data[0] & 0x04)!=0) && ((INP_data[1]&0x04)!=0))
{    OT_left_rear=2;
}

else if(((INP_data[0] & 0x04)==0) && ((INP_data[1]&0x04)!=0))
{    OT_left_rear=3;
}

//

if(((INP_data[0] & 0x08)==0) && ((INP_data[1]&0x04)==0))
{    OT_right_rear=0;
}

else if(((INP_data[0] & 0x08)!=0) && ((INP_data[1]&0x04)==0))
{    OT_right_rear=1;
}

else if(((INP_data[0] & 0x08)!=0) && ((INP_data[1]&0x04)!=0))
{    OT_right_rear=2;
}

else if(((INP_data[0] & 0x08)==0) && ((INP_data[1]&0x04)!=0))
{    OT_right_rear=3;
}

//

if((INP_data[2]&0x01)==0)
{
    if(timer_100ms<5)left_data=LEFT_off_pattern[OT_left_front];
    else left_data=LEFT_on_pattern[OT_left_front];
}
else
{    left_data=LEFT_on_pattern[OT_left_front];
}


if((INP_data[2]&0x02)==0)
{    if(timer_100ms<5)right_data=RIGHT_off_pattern[OT_right_front];
    else right_data=RIGHT_on_pattern[OT_right_front];
}
else
{    right_data=RIGHT_on_pattern[OT_right_fro
2樓: >>參與討論
avr
應(yīng)該是IAR V1.xx版本(icc90)下的產(chǎn)物
 
3樓: >>參與討論
soosan
謝謝AVR的指導(dǎo)!
謝謝AVR的指導(dǎo)!那位老師能否就如何移植到ICCAVR或者GCC上給我一些提示。謝謝!

4樓: >>參與討論
soosan
希望社區(qū)熱心的老師能給我一些參考!謝謝!
初次搞單片機(jī),希望能就這個(gè)項(xiàng)目入門。希望社區(qū)熱心的老師能給我一些參考!謝謝!

5樓: >>參與討論
avr
只是中斷函數(shù)聲明不一樣
只是中斷函數(shù)聲明不一樣,其它都很標(biāo)準(zhǔn),移植沒(méi)有很大的困難啊。

6樓: >>參與討論
cspdsy
中斷不一樣而已
#pragma interrupt_handler uart0_rx_isr:19
ICC里面中斷的聲明應(yīng)該是這樣的

7樓: >>參與討論
mymach
是啊,只是中斷和文件頭定義不太一樣
符合標(biāo)準(zhǔn)c語(yǔ)法的都不需要更改!


8樓: >>參與討論
soosan
謝謝各位,現(xiàn)給出移植后的代碼!
謝謝各位的指導(dǎo),我已移植成功!現(xiàn)帖出我移植后的代碼,希望高手指導(dǎo)并能給像我一樣的初學(xué)者一點(diǎn)參考!大家一起努力學(xué)AVR!
移植到ICCAVR
頭文件改為:
#include "iom8v.h"
#include "macros.h"
中斷改為:
#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
}

#pragma interrupt_handler int1_isr:3
void int1_isr(void)
{
}

#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{

}
移植到GCC:
頭文件改為:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
中斷改為:
SIGNAL(SIG_INTERRUPT0)
{
}

SIGNAL(SIG_INTERRUPT1)
{
}

SIGNAL(SIG_OVERFLOW0)
{
}

GCC編譯結(jié)果:
-------- begin --------
avr-gcc (GCC) 3.4.1
COPYRIGHT (C) 2004 Free SOFTWARE Foundation, Inc.
This is free SOFTWARE; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Size before:
outrigger.elf  :
section    size      addr
.text      1214         0
.data         0   8388704
.bss         36   8388704
.noinit       0   8388740
.EEPROM       0   8454144
.stab      2640         0
.stabstr   1820         0
Total      5710




Converting to AVR Extended COFF: outrigger.cof
avr-objcopy --debugging --change-section-address .data-0x800000 --change-section-address .bss-0x800000 --change-section-address .noinit-0x800000 --change-section-address .EEPROM-0x810000  -O coff-ext-avr outrigger.elf outrigger.cof
Discarding local symbol outside any compilation unit: .do_copy_data_start
Discarding local symbol outside any compilation unit: .do_copy_data_loop
Discarding local symbol outside any compilation unit: .do_clear_bss_start
Discarding local symbol outside any compilation unit: .do_clear_bss_loop

Size after:
outrigger.elf  :
section    size      addr
.text      1214         0
.data         0   8388704
.bss         36   8388704
.noinit       0   8388740
.EEPROM       0   8454144
.stab      2640         0
.stabstr   1820         0
Total      5710



Errors: none
-------- end --------


> PROCESS Exit Code: 0

ICCAVR編譯結(jié)果:
C:\icc\bin\imakew -f outrigger.mak
    ICCAVR -o outrigger -LC:\icc\lib\ -g -Wl-W -bfunc_lit:0x26.0x2000 -dram_end:0x45f -bdata:0x60.0x45f -dhwstk_size:16 -bEEPROM:1.512 -fihx_coff -S2 @outrigger.lk  
DEVICE 16% full.
Done.


參與討論
昵稱:
討論內(nèi)容:
 
 
相關(guān)帖子
對(duì)初學(xué)者怎樣才能學(xué)好單片機(jī)
問(wèn)個(gè)很菜的問(wèn)題哦!
用IBM 41T筆記本能用ISP功能嗎?我試了很多次都不行!臺(tái)式機(jī)可以
可以C調(diào)用的BIN到BCD轉(zhuǎn)換(for AVR)
大家誰(shuí)知道如何取得ATMEL樣片?網(wǎng)站上好象沒(méi)有樣片的鏈接!
免費(fèi)注冊(cè)為維庫(kù)電子開發(fā)網(wǎng)會(huì)員,參與電子工程師社區(qū)討論,點(diǎn)此進(jìn)入


Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號(hào)