s5pv210裸機串口無響應

程序代碼如下,

#define GPC0CON        *((volatile unsigned int *)0xe0200060)

#define GPC0DAT*((volatile unsigned int *)0xe0200064)

 

#define GPA0CON*((volatile unsigned int *)0xe0200000)

#define GPA0DAT*((volatile unsigned int *)0xe0200004)

#define ULCON1          *((volatile unsigned int *)0xe2900400)

#define UCON1 *((volatile unsigned int *)0xe2900404)

#define UFCON1          *((volatile unsigned int *)0xe2900408)

#define UMCON1         *((volatile unsigned int *)0xe290040c)

#define UTRSTAT          *((volatile unsigned int *)0xe2900410)

#define UERSTAT          *((volatile unsigned int *)0xe2900414)

#define UFSTAT1          *((volatile unsigned int *)0xe2900418)

#define UMSTAT1         *((volatile unsigned int *)0xe290041c)

#define UTXH1 *((volatile unsigned int *)0xe2900420)

#define URXH1 *((volatile unsigned int *)0xe2900424)

#define UBRDIV1          *((volatile unsigned int *)0xe2900428)

#define UDIVSLOT        *((volatile unsigned int *)0xe290042c)

#define UINTP1 *((volatile unsigned int *)0xe2900430)

#define UINTSP1           *((volatile unsigned int*)0xe2900434)

#define UINTM1            *((volatile unsigned int*)0xe2900438)

 

void delay(volatileunsigned int t)

{

            volatile unsigned int base = 0xa000;

            while(t--)

            {

                        for(base=0xa000;base;--base);

            }

}

 

voidled_tip(unsigned int control)

{

            volatile unsigned int temp;

            if(control==0x03)/*燈1閃爍*/

            {

                        temp = ~GPC0DAT;

                        temp ^= ~(1<<3);

                        GPC0DAT = temp;

                        delay(4);

            }

            else if(control==0x0a)/*燈2閃爍*/

            {

                        temp = ~GPC0DAT;

                        temp ^= ~(1<<4);

                        GPC0DAT = temp;

                        delay(4);

            }

            else if(control==0x30)/*雙燈交替閃爍*/

            {

                        GPC0DAT = 0x08;

                        delay(2);

                        GPC0DAT = 0x10;

                        delay(2);

            }

            else if(control==0xa0)/*雙燈同閃*/

            {

                        GPC0DAT = 0x18;

                        delay(2);

                        GPC0DAT = 0;

                        delay(2);

            }

}

 

void led_init()

{

            GPC0CON |= 0x11<<12;

}

 

void uart_init()

{

            GPA0CON = 0x00220000;

            ULCON1 = 0x00000003;

            UCON1 = 0x00000005;

            UFCON1 = 0x00000001;

            UMCON1 = 0;

 

            UBRDIV1 = 34;

            UDIVSLOT = 0xdfdd;

}

 

static voidsend_byte(volatile unsigned char byte)

{

            while((UFSTAT1 &(1<<24)));

            UTXH1=byte;

}

 

static volatileunsigned char recv_byte()

{

            while(!(UFSTAT1 & 0xff))

            {

                        led_tip(0x03);

            }

            return URXH1;

}

 

voidputchar(volatile unsigned char c)

{

            send_byte(c);

            if(c=='\n') send_byte('\r');

}

 

volatile unsignedchar getchar()

{

            volatile unsigned char c;

            c = recv_byte();

            return c;

}

 

void puts(volatilechar *str)

{

            volatile char *p = str;

            while(*p) putchar(*p++);

            putchar('\n');

}

 

void uart()

{

            volatile unsigned char c;

            volatile unsigned int temp;

 

            led_init();

            uart_init();

 

            puts("puts your key and thelight will be changed");

            puts("1 led1");

            puts("2 led2");

 

            while(1)

            {

                        c = getchar();

                        putchar(c);

                        putchar('\r');

 

                        if(c=='1')

                        {

                                    //temp =GPC0DAT & (0x1<<3);

                                    //temp^=0;

                                    GPC0DAT =0x10;

                        }

                        else if(c=='2')

                        {

                                    //temp =GPC0DAT & (0x1<<4);

                                    //temp^=0;

                                    //GPC0DAT&= temp;

                                    GPC0DAT =0x08;

                        }

                        else

                        {

                                    GPC0DAT =0x18;

                        }

                        led_tip(0x0a);

            }

}

這裏出現的問題就是,

串口可以輸出提示信息,但是對於輸入沒有任何的反應,經過點燈的調試,知道在接收的函數裏面一直循環等待,uart()函數裏面的while循環裏面的點燈測試程序是沒有機會運行的。現在發現輸入1、2和發送字符1、2板子上的燈是有反應的,但是,輸入的字符並沒有顯示出來,這是爲什麼?

好吧,我現在發現這個錯誤了,尷尬並且表示非常的吃驚!問題代碼如下,


不知道爲什麼,這個地方需要換成’\n’或者不用,在後面判斷,最後的else是我現在才加的,不需要看。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章