LED Control Plz help

Discussion in 'Embedded Systems and Microcontrollers' started by desi.djay, Nov 22, 2008.

  1. desi.djay

    Thread Starter New Member

    Nov 22, 2008
    4
    0
    hey
    i m doing a project on PIC18F452 and using Visual basic 6.0 to control the PIC
    in the project VB will send a Byte to the PIC through a serial port and the PIC turn on a LED with that Byte
    i have the sample of my old lab
    (LIGHT
    bsf PORTA,RA1
    bsf PORTA,RA2
    bsf PORTA,RA3
    movlw 128
    cpfseq SAVEBYTE
    bcf PORTA,RA2
    movlw 2
    bcf PORTA,RA3
    movlw 5
    bcf PORTA,RA1
    return)
    so could u guys help me figure out to turn on a LED PORTA RA1 with one byte and. then turn it of with a different byte
    and turn of POTRA,RA2 with a different byte. and so on... with assembly language or MikroBasic or MikroC.

    plz help. me figure out this.

    thanx.. :(
     
    Last edited: Nov 22, 2008
  2. gvr_p

    New Member

    Nov 5, 2008
    6
    0
    read the byte in received buffer and send it to the portA. The on/off sequence can be manupulated in VB on PC and send it to controller.
     
  3. Alberto

    Active Member

    Nov 7, 2008
    169
    36
    One byte is composed of 8 bits so you can control up to 8 leds! send 0 to turn them all off send 255 to turn them all on.

    1 led 1 on - all the other off
    2 led 2 on - all the other off
    4 led 3 on - all the other off
    8 led 4 on - all the other off
    16 led 5 on - all the other off
    32 led 6 on - all the other off
    64 led 7 on - all the other off
    128 led 8 on - all the other off

    With cobination number you can control all the 8 leds.


    B0 var Byte
    T9600 con 2
    Led var PortA.1

    NoByte:
    Toggle Led
    Serin portA.0,T9600,500,NoByte,[B0]
    PortB=B0
    goto NoByte

    The above code in basic need to be translated in your mikrobasic (but it should not be too different).
    Connect serial Rx to PortA0
    Connect a led via 330 ohms resistor to portA.1
    Connect 8 leds via 330 ohms resistor for each led to the IO of portB (one for each pin of 8 IO port)
    Send a byte via your PC and the leds should show up.

    Alberto
     
    Last edited: Nov 24, 2008
  4. desi.djay

    Thread Starter New Member

    Nov 22, 2008
    4
    0
    i did this code on mikro C but dont work..

    int x = 200 ; // Code recieved from Computer


    setup()
    {
    USART_init(19200); // initialize USART module
    // (8 bit, 19200 baud rate, no parity bit...)

    // Configure ports as OUTPUT
    TRISA = 0 ;
    TRISB = 0 ;

    // Initiallize ports
    PORTA.F0 = 1 ;
    PORTA.F1 = 0 ;
    PORTA.F2 = 0 ;
    PORTA.F3 = 1 ;
    PORTA.F4 = 0 ;
    }
    void main() {

    //setup board
    setup();
    // Infinite Loop - continuosly run while powered on
    do {

    //if ( USART_Data_Ready() ) // if data is received
    // x = USART_Read() ; // read the received data

    switch(x)
    {
    case (1):
    PORTA.A1 = 1 ;
    PORTA.A2 = 0 ;
    PORTA.A3 = 0 ;
    break;
    case (2):
    PORTA.A1 = 0 ;
    PORTA.A2 = 1 ;
    PORTA.A3 = 0 ;
    break;
    case (10):
    PORTB.A1 = 0 ;
    PORTB.A2 = 0 ;
    PORTC.A3 = 1 ;
    break;
    }
    } while (1); //end do->while
     
    Last edited: Nov 24, 2008
  5. Alberto

    Active Member

    Nov 7, 2008
    169
    36
    I can't help you with mikroC. The only suggestion is slow down the baud rate. Set the port at a low value at the begining than when the system works, you can increase the speed till the system works .

    Alberto
     
  6. desi.djay

    Thread Starter New Member

    Nov 22, 2008
    4
    0
    thanx alberto . ...
    i tried all i could with. mikro c but no luck so im going with assembly language cuz i can get it to at least talk pc and turn on one light with the code i have on my first post. if u kno any thing assembly and could help i would really appreciate it.
    thanx
     
  7. Alberto

    Active Member

    Nov 7, 2008
    169
    36
    Can you tell me which is the frequency (in MHz) of the quartz or resonator of your circuit ?

    Your pic is a 40 pins ?

    Are you using a max232 for the serial connection to your PC or a simple resistor

    Alberto
     
    Last edited: Nov 26, 2008
  8. desi.djay

    Thread Starter New Member

    Nov 22, 2008
    4
    0
    yes its a RS232 serial connection
    same as this pic and circuit board http://www.picbook.com/
    it has a 10Mhz maximum oscillator speed
    4 independent timers
    17 interrupt sources

    and the PIC pins
    Total Pins are 40
    and I/O pins 33
    I/O PORTs 5

    1536 Byte ram
    16384 program memory 16bit word
     
Loading...