Serial Communication

Embed Size (px)

DESCRIPTION

serial communication

Citation preview

  • laires ( : ) . 232SR

    ===== . no acunimmoC laireS 232SR

    .

    . :

    . TRASU

    ( ) . XT XR

  • yrarbiL TRASU . .

    TRASU : . etarduab

    ;)0042(tinI_trasU

    0069 . :

    ;)0069(tinI_trasU

    . XT XR

    :

    ;)(ydaeR_ataD_trasU

    1 ( ) ( . )

    :

    {)1==)(ydaer_atad_trasu(fi

    .

    }

    . : pool .

  • :pool

    {)1==)(ydaer_atad_trasu(fi

    }

    ;pool otog

    ( TRASU ) .

    :

    . etyb .

    .

    ' ' ) . edoC IICSA

    ( .

    ;)(daeR_trasU

    ;)(daer_trasu=atad

    . {)'A'==atad(fi

    A

    }

  • G : . 0C DEL

    ;pool otog :pool )1(elihw . ( )

    :

    {)1==)(ydaer_atad_trasu(fi

    {))(ydaer_atad_trasu(fi

    . . 1==

    .

    ;atad rahc

    )(niam diov

    tuptuo era ctrop lla // ;0=csirt {

    0069 si deeps // ;)0069(tinI_trasU {)1(elihw

    atad gniviecer nehw // {)1==)(ydaer_atad_trasu(fi

    elbairav ni ti erots dna atad daer // ;)(daer_trasu=atad

    ;1=0f.ctrop )'G'==atad(fi

    }

    }

    }

    ;)'y'(etirW_trasU

  • . y ( esac reppu )

    . esac rewol

    . .

    ) ( .

    3

    9 1

    7 2

    4 3

    2 5

    6

    5 7

    1 8

    6 9

    ( )

  • char y=0;

    void main() {

    Usart_Init(9600);

    while(1){

    if (Usart_Data_Ready()) { // If data is received

    y = Usart_Read(); // Read the received data

    if(y=='0') usart_write('3');

    if(y=='1') usart_write('9');

    if(y=='2') usart_write('7');

    if(y=='3') usart_write('4');

    if(y=='4') usart_write('8');

    if(y=='5') usart_write('2');

    if(y=='6') usart_write('0');

    if(y=='7') usart_write('5');

    if(y=='8') usart_write('1');

    if(y=='9') usart_write('6');

    }

    }

    }

  • !sey damha . oN

    . ;0=y

    . .

    ;i trohs dengisnu

    ;]5[x rahc

    ;"!sey "=][txet rahc

    ;1c,1b,1a rahc ;0=y rahc

    )][txet rahc(gnirts diov

    {

    )++y;5

  • "damha"

    y "!sey "

    . "oN " . . ;0=y

    . ( yalp pots )

    . tpurretni

    ( ).

    . tpurretni

    . NOCTNI NOCTNI

    . )(niam diov

    . tpurretni fi

    . galf tpurretni

    ===========================

    tpurretni . TRASU

    ( ) 0a 'a'

    .

  • ;mm rahc

    )(tpurretni diov

    {

    ;)(daer_trasu=mm{))(ydaer_atad_trasu(fi

    ;)'a'(etirw_trasu

    }

    ;0=5f.1rip

    ;nruter

    }

    )(niam diov

    ;70x0=nocmc{

    ;0=asirt

    ;1=6F.NOCTNI;1=7f.NOCTNI

    ;1=5f.1EIP

    ;)0069(tinI_trasU

    };)005(sm_yaled;0=0f.atrop;)005(sm_yaled;1=0f.atrop{)1(elihw

    }

    )(niam diov :

    tpurretni . ;nruter

    :

    atrop ;70x0=nocmc ( .a826f61cip ) . latigid

    ;1=6F.NOCTNI ;1=7f.NOCTNI . noctni .

    1eip ;1=5f.1EIP . trasu

  • 0A .

    . tpurretni

    fi

    0B . ( . 0B )

    . fi

    )(tpurretni diov

    {

    } { )0==0f.btrop(fi

    {)1==5f.1rip(fi }

    ..

    }

    1RIP . 232SR

    {))(ydaer_atad_trasu(fi 1RIP .

    tpurretni

    ;0=5f.1rip

    . ;0= ni.noctni tpurretni lanretxe 0B

    .

  • . TRASU : .

    . 232SR

    .

    - :

    tinI_traU_tfoS daeR_traU_tfoS etirW_traU_tfoS

    :

    ;)0 ,0069 ,2 ,1 ,BTROP(tinI_traU_tfoS

    XR 0069 . btrop . 2B XT 1B

    detrevni . .

    = atad ;)cer(daeR_traU_tfoS

    cer( retniop ) . atad .

    ydaer_atad . cer retniop

    cer .

    : N

    ;)'N'(etirW_traU_tfoS

  • N

    Char ppp='N';

    Soft_Uart_Write(ppp);

    :-

    char data =0, ro = 0; unsigned short *rec; void main() { rec = &ro; // so rec will be = 0 ; // Init (8 bit, 2400 baud rate, no parity bit..) Soft_Uart_Init(PORTB, 1, 2, 2400, 0); While(1) { while (!*rec){ data = Soft_Uart_Read(rec); // Receive data if(data=='m') Soft_Uart_Write('a'); } } }//~!

    m a .

    : -

    While(!*rec) while(*rec==0) .