Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Mikrobasic help..

Status
Not open for further replies.

mramos1

Active Member
My last chance before I go to assembler again. Below is an attempt to read a VDD/VSS pot on A.0 and blink an LED on B.0 (maybe I should move it to B3 like William said use PWM). 8mhz internal osc 16F88.

Anyway in MPLABS I see the ADC works (range 0-255 no problem) and I see the value load in "count" and "value" before calling the Vdelay_ms routine. The LED blinks but no change in the speed and it is very slow 100ms (50/50).

I can only assume I do not have some pic register set correctly. Any ideas?
I thought TRISB = 0 would make it all output..

Code:
program P16f88
    Symbol LED = 0
    Symbol POT = 0
    dim count as word
    dim value as byte
main:
  TRISA  = $FF                   ' PORTA is input
  PORTB  = 0
  TRISB  = $00                   ' Pins PORTB output
'  ADCON0 = $81                    'Configure analog inputs and Vref
  ADCON1 = $80
'  ANSEL  = $81
    value=adc_read(POT)
    DO
    count=value
        ClearBit(PORTB,LED)
    VDelay_MS(count)
        SETBIT(PORTB,LED)
    VDelay_MS(count)

  LOOP until 1 = 0
end.
 
Are you setting the INTOSC to 8-MHz somewhere in that code? If you don't set the OSCCON register INTOSC defaults to 31.25-KHz.

Here's how I do it in assembler;

Code:
;******************************************************************

        org     0x0000
Start
        clrf    STATUS          ;                                 |B0
        clrf    PORTA           ;                                 |B0
        clrf    PORTB           ;                                 |B0
        goto    Init            ;                                 |B0
;
;  program initialization
;
Init    bsf     STATUS,RP0      ; bank 1                          |B1
        clrf    ANSEL           ; setup PORT A for digital I/O    |B1
;
;  setup INTOSC for 8-MHz operation
;
        movlw   b'01110000'     ;                                 |B1
        movwf   OSCCON          ; select 8-MHz INTOSC clock       |B1
Stable  btfss   OSCCON,IOFS     ; INTOSC frequency stable?        |B1
        goto    Stable          ; no, branch and wait             |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
;
 
Hey Mike..

The int osc is working as well the adc, I looked at them in MPLABS. It is a commercial compiler so I do not suspect vdelay_ms routing that is getting pass the value.

Just for some reason portb.0 it blinking at a contact.

I have a pot on a.0 and led on b.0..

Maybe I need to learn the adc in assembler and just pick an 12F pic pin and a 16f pic and stay in one area :)
 
Last edited:
I've not played with mikrobasic but shouldn't you have the adc read statment inside the loop? also, I'm not sure if you are giving the adc time to sample. You need to give it time to sample and then convert. Maybe adc_convert does the right thing but there is no way to know.

also, you say you see the values in MPLABs, are you using the simulator? You are seeing 0-255 but the F88 has a 10 bit adc (0-1023) so something isn't right there.
 
philba said:
I've not played with mikrobasic but shouldn't you have the adc read statment inside the loop? also, I'm not sure if you are giving the adc time to sample. You need to give it time to sample and then convert. Maybe adc_convert does the right thing but there is no way to know.

I assume the adc_read code does the waiting and grabbing of the data (from the manual it looked that way). Also, the adc_read was in the loop, I thought maybe that was the reason for the slow square wave (their adc routine waiting on the value) and it was stretching it out, so I moved it out of the loop and I just reset in MPLABS after I turned the pot.

also, you say you see the values in MPLABs, are you using the simulator? You are seeing 0-255 but the F88 has a 10 bit adc (0-1023) so something isn't right there.

I had a "word" at first and I was getting back two bytes of data (stored at $20 and $21). Then I read in there help adc_read(byte) to I flipped to a byte. And with the pot turned from one end to the other I get 0-FF (ok I saw 0 - EB without turning it all the way on one end) no problem in MPLABS with ICD2 and the adc_read, it is the darn portb.0 not going up and down that is killing me. That part seems simple. Weird though.

I will try more changed in a bit, as I have no square wave at all now.
 
by the way, you say the blink rate is slow? yet you said it was 100 mS. that's pretty fast, almost too fast to see. based on your code, the max rate should be 510 mS frequency (255 on, 255 off).

anyway, take out the adc code and just get the blinking LED working. once you've got that, then add the ADC back in.
 
I can see the LED is blinking very very fast, and it is 200ms+, not 100.. Sorry my mistake..

I moved the adc outside of the loop, but probably better remove the adc code like you said and see if portb.0 works.

UPDATE: new code

Looks like portB is not output. Gonna check proto board. This should blink the LED..

Code:
program P16f88
    Symbol LED = 0
    Symbol POT = 0
    dim count as word
    dim value as byte
main:
  TRISA  = $FF                   ' PORTA is input
  PORTB  = 0
  TRISB  = $00                   ' Pins PORTB output
'  ADCON0 = $81                    'Configure analog inputs and Vref
'  ADCON1 = $80
'  ANSEL  = $81
'    value=adc_read(POT)
  value =50
    DO
    count=value
        ClearBit(PORTB,LED)
    VDelay_MS(count)
        SETBIT(PORTB,LED)
    VDelay_MS(count)

  LOOP until 1 = 0
end.
 
Last edited:
Philba:

I have a scope on it as well so even without the LED I can see it. I think I have a protoboard problem, it is an old board from a pile I had in a box. I will rebuild it on another one. I have dealt with connection issues on and off all day as well.

But I did find a method to do MikroBASIC and MPLABS, so that is good.

Thanks for your input. But I think it is the protoboard.

This was a learn the ICD2 project (that ate my Sunday but I had fun).

Figured a POT and LED and not etch a curcuit board (much as I like to do that) just plug it all in.

Also running on 2 double A batteries. I had 2.6V the last check. But the datasheet said it should run that low. Next round I will get a 5VDC reg PS hooked in..

Has to be the protoboard. And I replaced the 16F88 as well.

I will start it all over, it was fast to wire up.
 
ok. if you have a solderless breadboard, you could just build it on that. I do it all the time. good luck - I hate it when the tools are messed up.
 
Too many new things maybe. Learning ICD2 (I like it) via MikroBASIC (using MPLABS view memory mode and viewing the MikroBASIC .ASM file in another program; it is not bad) on an old solderless breadboard. I think it is the breadboard.

I had power going away on and off and pulses disappearing to the LED on and off all day.. Wiggle them and back in service. But the ICD2 programmed it everytime so I ignored the wiggle the wires.

One thing I did learn, do not set MCLR as RA5 and program it for INT OSC.. I have one chip sitting to re-write with the old programmer and undo that. Maybe it needs that pin to program the chip DUH!

I would think I would have had trouble getting the ADC working, not blinking an LED.

In the past, I normally debug via an LED and delay on a pin (509, 628A, 629, 675, 683). But the 16F88 and ICD2 are all new to me. I still think it is the protoboard at this point.

Thanks for your help. I think I should rebuild it on another protoboard. It was old and the wires were on it as well (OLD).
 
code for counting

hello, can i have a code for programing a pic16f84 and a 3 7segment to count from 0 t0 123 and 0 t0 59, by the used of microbasic.. pls... let me have one.. tnx..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top