pic16f877a display 7 segments with input from rs232

Discussion in 'Programmer's Corner' started by summeranson, Mar 31, 2009.

  1. summeranson

    Thread Starter Member

    Feb 12, 2009
    28
    0
    hi all experts.. i need some help here..
    my project is to create a program which read the input from pc keyboard through rs232 to compare it whether it is correctly key in according to the snellen chart..

    i have done the program but it just doesnt work on my hardware...
    i am using pic-c compiler..

    can anybody please help me to check if my program got any problem???

    thousands appreciate to all experts who can help me out...

    *beg* *beg*

    following is my program

    /////////////////////////////////////////////////////////////////////////
    //// Configure the CCS prototype card as follows: ////
    //// LED seg a Pin B0 ////
    //// LED seg b Pin B1 ////
    //// LED seg c Pin B2 ////
    //// LED seg dp Pin B3 ////
    //// LED seg d Pin B4 ////
    //// LED seg e Pin B5 ////
    //// LED seg f Pin B6 ////
    //// LED seg g Pin B7 ////
    /////////////////////////////////////////////////////////////////////////
    #if defined(__PCB__)
    #include <16C56.h>
    #fuses HS,NOWDT,NOPROTECT
    #use delay(clock=20000000)
    #use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)
    #elif defined(__PCM__)
    #include <16F877a.h>
    #fuses HS,NOWDT,NOPROTECT,NOLVP
    #use delay(clock=20000000)
    #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
    #elif defined(__PCH__)
    #include <18F452.h>
    #fuses HS,NOWDT,NOPROTECT,NOLVP
    #use delay(clock=20000000)
    #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
    #endif
    char input;
    int score;
    //0,1,2,3,4,5,6,7,8,9,all light up
    BYTE CONST LED_MAP[11] = {0x88,0xf9,0x4c,0x68,0x39,0x2a,0x0b,0xf8,0x08,0x38,0xff};
    ////////////////LED OUTPUT DISPLAY///////////////////
    void ending (void)
    {
    switch (score){
    case 0:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[0]);
    output_d(LED_MAP[0]);
    break;
    case 1:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[0]);
    output_d(LED_MAP[1]);
    break;
    case 3:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[0]);
    output_d(LED_MAP[3]);
    break;
    case 5:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[0]);
    output_d(LED_MAP[5]);
    break;
    case 8:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[0]);
    output_d(LED_MAP[8]);
    break;
    case 11:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[1]);
    output_d(LED_MAP[1]);
    break;
    case 14:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[1]);
    output_d(LED_MAP[4]);
    break;
    case 18:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[1]);
    output_d(LED_MAP[8]);
    break;
    case 22:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[2]);
    output_d(LED_MAP[2]);
    break;
    case 26:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[2]);
    output_d(LED_MAP[6]);
    break;
    case 30:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[3]);
    output_d(LED_MAP[0]);
    break;
    case 35:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[3]);
    output_d(LED_MAP[5]);
    break;
    case 40:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[4]);
    output_d(LED_MAP[0]);
    break;
    case 45:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[4]);
    output_d(LED_MAP[5]);
    break;
    case 50:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[5]);
    output_d(LED_MAP[0]);
    break;
    case 55:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[5]);
    output_d(LED_MAP[5]);
    break;
    case 61:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[6]);
    output_d(LED_MAP[1]);
    break;
    case 67:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[6]);
    output_d(LED_MAP[7]);
    break;
    case 73:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[7]);
    output_d(LED_MAP[3]);
    break;
    case 79:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[7]);
    output_d(LED_MAP[9]);
    break;
    case 85:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[8]);
    output_d(LED_MAP[5]);
    break;
    case 91:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[9]);
    output_d(LED_MAP[1]);
    break;
    case 98:
    output_e(LED_MAP[10]);
    output_b(LED_MAP[9]);
    output_d(LED_MAP[8]);
    break;
    case 105:
    output_e(LED_MAP[1]);
    output_b(LED_MAP[0]);
    output_d(LED_MAP[5]);
    break;
    case 112:
    output_e(LED_MAP[1]);
    output_b(LED_MAP[1]);
    output_d(LED_MAP[2]);
    break;
    case 119:
    output_e(LED_MAP[1]);
    output_b(LED_MAP[1]);
    output_d(LED_MAP[9]);
    break;
    case 126:
    output_e(LED_MAP[1]);
    output_b(LED_MAP[2]);
    output_d(LED_MAP[6]);
    break;
    case 133:
    output_e(LED_MAP[1]);
    output_b(LED_MAP[3]);
    output_d(LED_MAP[3]);
    break;
    case 140:
    output_e(LED_MAP[1]);
    output_b(LED_MAP[4]);
    output_d(LED_MAP[0]);
    break;
    case 147:
    output_e(LED_MAP[1]);
    output_b(LED_MAP[4]);
    output_d(LED_MAP[7]);
    break;
    }
    }
    ////////////////////////////////////////////////
    void v2 (void)
    {
    if ((input = getc()) == 'v')
    {score=score+7;
    ending();}
    else
    { ending();}
    }
    void o4 (void)
    {
    if ((input = getc()) == 'o')
    {score=score+7;
    v2();}
    else
    { ending();}
    }
    void a4 (void)
    {
    if ((input = getc()) == 'a')
    {score=score+7;
    o4();}
    else
    { ending();}
    }
    void h3 (void)
    {
    if ((input = getc()) == 'h')
    {score=score+7;
    a4();}
    else
    { ending();}
    }
    void t3 (void)
    {
    if ((input = getc()) == 't')
    {score=score+7;
    h3();}
    else
    { ending();}
    }
    void x4 (void)
    {
    if ((input = getc()) == 'x')
    {score=score+7;
    t3();}
    else
    { ending();}
    }
    void u4 (void)
    {
    if ((input = getc()) == 'u')
    {score=score+7;
    x4();}
    else
    { ending();}
    }
    void y3 (void)
    {
    if ((input = getc()) == 'y')
    {score=score+7;
    u4();}
    else
    { ending();}
    }
    void x3 (void)
    {
    if ((input = getc()) == 'x')
    {score=score+6;
    y3();}
    else
    { ending();}
    }

    void u3 (void)
    {
    if ((input = getc()) == 'u')
    {score=score+6;
    x3();}
    else
    { ending();}
    }
    void o3 (void)
    {
    if ((input = getc()) == 'o')
    {score=score+6;
    u3();}
    else
    { ending();}
    }
    void y2 (void)
    {
    if ((input = getc()) == 'y')
    {score=score+6;
    o3();}
    else
    { ending();}
    }
    void a3 (void)
    {
    if ((input = getc()) == 'a')
    {score=score+6;
    y2();}
    else
    { ending();}
    }
    void h2 (void)
    {
    if ((input = getc()) == 'h')
    {score=score+6;
    a3();}
    else
    { ending();}
    }
    void t2 (void)
    {
    if ((input = getc()) == 't')
    {score=score+5;
    h2();}
    else
    { ending();}
    }
    void x2 (void)
    {
    if ((input = getc()) == 'x')
    {score=score+5;
    t2();}
    else
    { ending();}
    }
    void a2 (void)
    {
    if ((input = getc()) == 'a')
    {score=score+5;
    x2();}
    else
    { ending();}
    }
    void u2 (void)
    {
    if ((input = getc()) == 'u')
    {score=score+5;
    a2();}
    else
    { ending();}
    }
    void v (void)
    {
    if ((input = getc()) == 'v')
    {score=score+5;
    u2();}
    else
    { ending();}
    }
    void o2 (void)
    {
    if ((input = getc()) == 'o')
    {score=score+4;
    v();}
    else
    { ending();}
    }
    void y (void)
    {
    if ((input = getc()) == 'y')
    {score=score+4;
    o2();}
    else
    { ending();}
    }
    void t (void)
    {
    if ((input = getc()) == 't')
    {score=score+4;
    y();}
    else
    { ending();}
    }
    void h (void)
    {
    if ((input = getc()) == 'h')
    {score=score+4;
    t();}
    else
    { ending();}
    }
    void a (void)
    {
    if ((input = getc()) == 'a')
    {score=score+3;
    h();}
    else
    { ending();}
    }
    void u (void)
    {
    if ((input = getc()) == 'u')
    {score=score+3;
    a();}
    else
    { ending();}
    }
    void x (void)
    {
    if ((input = getc()) == 'x')
    {score=score+3;
    u();}
    else
    { ending();}
    }
    void g (void)
    {
    if ((input = getc()) == 'g')
    {score=score+2;
    x();}
    else
    { ending();}
    }
    void o (void)
    {
    if ((input = getc()) == 'o')
    {score=score+2;
    g();}
    else
    {ending();}
    }
    main()
    {
    int countdown;
    set_tris_b(0);
    set_tris_d(0);
    set_tris_e(0);
    //blink the 7 segments
    output_b(0);
    output_d(0);
    for (countdown = 50 ; countdown != 0 ; countdown--)
    {
    delay_us(10);
    }
    output_b(1);
    output_d(1);
    //end of blinking
    score = 0;
    if ((input = getc()) == 'e')//start the input from pc keyboard through rs232
    {++score;
    o();}
    else
    { ending();}
    return 0;
    }
     
Loading...