在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > AVR單片機Atmega128外擴RAM

            AVR單片機Atmega128外擴RAM

            作者: 時間:2013-12-12 來源:網(wǎng)絡(luò) 收藏


            //unsigned char readram(unsigned int iaddr);
            void port_init(void);
            void uart1_init(void);
            //void writeram(unsigned int iaddr, unsigned char ctemp);
            void test_ram(void);
            void test_net(void);
            //void sendstring1(unsigned int * txbuf);

            char char2hex(char t1)
            {
            if((t1>=00) (t1=0x09))
            {
            t1=t1+0x30;//'0'--'9'
            }
            else
            {
            if((t1>=0x0a)(t1=0x0f))//'A'--'F'
            t1=t1-0x0a+0x61;
            }
            return t1;
            }

            void sendinthex1(unsigned int c)
            {
            char temph=0,templ=0;
            char t1=0,t2=0;
            temph=c/256;
            templ=c%256;
            t1=(c/256)/16;
            //t1=t1>>8;
            UDR1 = char2hex(t1);
            while(!(UCSR1A 0x40));
            UCSR1A |=0x40;
            t1=(c/256)%16;
            UDR1 = char2hex(t1);
            while(!(UCSR1A 0x40));
            UCSR1A |=0x40;
            t2=(c%256)/16;//templ0xf0;
            //t2=t2>>8;
            UDR1 = char2hex(t2);
            while(!(UCSR1A 0x40));
            UCSR1A |=0x40;
            t2=(c%256)%16;//templ0x0f;
            UDR1 = char2hex(t2);
            while(!(UCSR1A 0x40));
            UCSR1A |=0x40;
            }

            void sendchar1(char c) // 發(fā)送
            {
            UDR1 = c;
            while(!(UCSR1A 0x40));
            UCSR1A |=0x40;
            }

            void sendint1(unsigned int c) // 發(fā)送
            {
            UDR1 = (c0xff00)>>8;
            while(!(UCSR1A 0x40));
            UCSR1A |=0x40;
            UDR1 = c0xff;
            while(!(UCSR1A 0x40));
            UCSR1A |=0x40;
            }

            void sendstring1(unsigned char * txbuf) // 發(fā)送
            {
            unsigned int j;
            for (j = 0; *txbuf; j++, txbuf++)
            sendchar1(*txbuf);
            }

            void port_init(void)
            {
            //PA AD0-AD7 地址
            //PC AD8-AD15
            PORTA = 0xFF;
            DDRA = 0xFF;

            PORTC = 0xFF; //m103 output only
            DDRC = 0x00;

            //PB4 NETRST O

            PORTB = 0xFF;
            DDRB = 0x10;

            PORTD = 0xFF;
            DDRD = 0x00;

            PORTE = 0xFF;
            DDRE = 0x00;

            PORTF = 0xFF;
            DDRF = 0x00;

            PORTG = 0x1F;
            DDRG = 0x00;
            }

            //UART0 initialisation
            // desired baud rate:115200
            // actual baud rate:111111 (3.7%)
            // char size: 8 bit
            // parity: Disabled
            /*
            void uart0_init(void)
            {
            UCSR0B = 0x00; //disable while setting baud rate
            UCSR0A = 0x00;
            UCSR0C = 0x06;

            // UBRRL = (fosc / 16 / (baud + 1)) % 256;
            // UBRRH = (fosc / 16 / (baud + 1)) / 256;

            UBRR0L = (F_CPU / 16 / (baud + 1)) % 256;//0x03;//0x08; //set baud rate lo
            UBRR0H = (F_CPU / 16 / (baud + 1)) / 256;//0x00; //set baud rate hi
            UCSR0B = 0x18;//0x98;
            }
            */

            //UART1 initialisation
            // desired baud rate:115200
            // actual baud rate:111111 (3.7%)
            // char size: 8 bit
            // parity: Disabled
            void uart1_init(void)
            {
            UCSR1B = 0x00; //disable while setting baud rate
            UCSR1A = 0x00;
            UCSR1C = (1UCSZ11)|(1UCSZ10);//8bit+1bit stop
            UBRR1L=(fosc/16/(baud+1))%256;
            UBRR1H=(fosc/16/(baud+1))/256;
            UCSR1B =(1RXEN1)|(1TXEN1);//RXCEN TXCEN
            }

            /*
            #pragma interrupt_handler int0_isr:2
            void int0_isr(void)
            {
            //external interupt on INT0
            }
            */

            //call this routine to initialise all peripherals
            void init_devices(void)
            {
            cli(); //disable all interrupts
            port_init();
            uart1_init();
            }

            #if 0

            unsigned char readram(unsigned int iaddr)
            {
            //unsigned char caddl,caddh;
            unsigned char cdatatemp=0;
            RDH;
            WRH;
            ALEH;
            DDRA = 0xFF;
            DDRC = 0xFF;
            PORTC=iaddr>>8;
            PORTA=(unsigned char)iaddr;
            asm("nop;");
            ALEL; //LATCH IT
            DDRA = 0x00;//PORT INPUT
            RDL;
            // send wr
            asm("nop;");
            cdatatemp=PINA;
            RDH;
            ALEH;
            return cdatatemp;
            }


            關(guān)鍵詞: AVR單片機 Atmega128 外擴RAM

            評論


            相關(guān)推薦

            技術(shù)專區(qū)

            關(guān)閉