Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Mikrobasic and 4 7-segment displays

Status
Not open for further replies.

SparkyChem

Member level 3
Joined
Apr 22, 2010
Messages
57
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Lima, Peru
Activity points
2,084
Hello out there. I need some help. Does anybody has a code to share made with Mikrobasic that actually works.? I need to make a counter to drive 4 seven segment displays on PIC16F628A using Mikrobasic.:???:
 

Very clever Re: Mikrobasic and 4 7-segment displays

Take a look here: https://www.edaboard.com/threads/193784/#post826118

That uses a PIC16F88 to drive 3 7-segments. It is a thermometer code. But you should get the idea.

Hope this helps.
Tahmid.

Hello there, your code is very good and it gave me an idea on how to adapt it for ADC, but what i dont understand is how do i manage to change it for using Common cathode displays?. I see you dont use interrupts. Is this necessary for my application (ex. an stopwatch or decreasing/increasing counter).?. How do i make it to work for counting?.

Thanks in advance. :)
 

In the mikroBASIC compiler window, go to Tools (Alt + T), go to 7 Segment Editor. There, select the numbers as necessary and you'll get required values for common anode and common cathode.

In the hardware, where the NPN transistor sources current to the displays, the circuit configuration is base from signal, emitter to display and collector to +5v. Change that so that, base is from signal, emitter is connected to ground and collector is connected to the common cathode point (to the display).

Use an interrupt to detect time, so that a flag is raised every second. In the main code, check if the flag is raised. When the flag is raised, increment the value of the counter, whose value is used to display time. Then clear the flag.

Hope this helps.
Tahmid.
 

Im learning Re: Mikrobasic and 4 7-segment displays

In the mikroBASIC compiler window, go to Tools (Alt + T), go to 7 Segment Editor. There, select the numbers as necessary and you'll get required values for common anode and common cathode.

In the hardware, where the NPN transistor sources current to the displays, the circuit configuration is base from signal, emitter to display and collector to +5v. Change that so that, base is from signal, emitter is connected to ground and collector is connected to the common cathode point (to the display).

Use an interrupt to detect time, so that a flag is raised every second. In the main code, check if the flag is raised. When the flag is raised, increment the value of the counter, whose value is used to display time. Then clear the flag.

Hope this helps.
Tahmid.

Hello i did what you said and i managed to make your code for the thermometer to work for Common cathode display. At least it works this way on proteus (ISIS), i still can't figure out how to do the stuff you say about interrupt. Can you show to me how to do it? :smile:

I understand this part is where you drive the outputs from PortA to activate each display but i feel for some way its tied only to that port

Code:
select case seven
           case 1 num7 = 2 
           case 2 num7 = 4 
           case 3 num7 = 8 
    end select

But what if i want to do it from Portb. Let's say starting from Portb.7 and then going on to Porta.1 and porta.2, leaving porta.3 unused, Is it possible to do this? How do you assign the ports so they can activate each display?

Code:
temperature = (ADC_Read(0) * 500) >> 10

This part takes analog to digital convertion for channel 0 in the PIC but what's the meaning of the ">>" operator?. Why is it multiplied by 500?

Maybe i ask too many questions but i wish to learn about it. Thanks in advance. :)
 

Re: Im learning Re: Mikrobasic and 4 7-segment displays

I understand this part is where you drive the outputs from PortA to activate each display but i feel for some way its tied only to that port

Code:
select case seven
           case 1 num7 = 2 
           case 2 num7 = 4 
           case 3 num7 = 8 
    end select

But what if i want to do it from Portb. Let's say starting from Portb.7 and then going on to Porta.1 and porta.2, leaving porta.3 unused, Is it possible to do this? How do you assign the ports so they can activate each display?

In that case, you can access individual bits. Let's just use the above example and I'll explain with that:
Code:
select case seven
           case 1 num7 = 2 
           case 2 num7 = 4 
           case 3 num7 = 8 
    end select
PORTA = num7

num7 = 2 means RA1 is high. num7 = 4 means RA2 is high. num7 = 8 means RA3 is high.
So, instead of writing num7 = 2, write
Code:
RA1_bit = 1
RA2_bit = 0
RA3_bit = 0
Remove the PORTA = num7 at the bottom

Instead of writin num7 = 4, write
Code:
RA2_bit = 1
RA1_bit = 0
RA3_bit = 0

I hope you get the idea now.

Code:
temperature = (ADC_Read(0) * 500) >> 10

This part takes analog to digital convertion for channel 0 in the PIC but what's the meaning of the ">>" operator?. Why is it multiplied by 500?

Maybe i ask too many questions but i wish to learn about it. Thanks in advance. :)

>> means bit shift right.
The value of the ADC output is between 0 and 1023. >> 10 means bit shift to the right 10 times, which basically just means /1024, but executes faster.
So, the statement just scales the ADC output value to the range 0 to 500.

Hope this helps.
Tahmid.
 

Re: Im learning Re: Mikrobasic and 4 7-segment displays

In that case, you can access individual bits. Let's just use the above example and I'll explain with that:
Code:
select case seven
           case 1 num7 = 2 
           case 2 num7 = 4 
           case 3 num7 = 8 
    end select
PORTA = num7

num7 = 2 means RA1 is high. num7 = 4 means RA2 is high. num7 = 8 means RA3 is high.
So, instead of writing num7 = 2, write
Code:
RA1_bit = 1
RA2_bit = 0
RA3_bit = 0
Remove the PORTA = num7 at the bottom

Instead of writin num7 = 4, write
Code:
RA2_bit = 1
RA1_bit = 0
RA3_bit = 0

I hope you get the idea now.



>> means bit shift right.
The value of the ADC output is between 0 and 1023. >> 10 means bit shift to the right 10 times, which basically just means /1024, but executes faster.
So, the statement just scales the ADC output value to the range 0 to 500.

Hope this helps.
Tahmid.

Hello,

I read through your explanation and after making the proper arrangements in the code, now it works. it was not hard. i forgot using PortB.7=1 individually doesnt function this way to turn on that 7-segment display on mikrobasic.

Besides this, I have a couple of questions regarding your code for ADC. Where do you assign the bits for ADC conversion? How do you tell mikrobasic you want the ADC is 10-bits and not let's say 8-bit or less?

If instead connecting the LM35 i want to put a potentiometer with its wiper tied to the analog input of the microcontroller and use it as a voltmeter. how do i change it so it can work that way? in other words, what if i want to make the displays show two decimals on the right side of the integer digit for example let's say a result of 3.12 Volts?

By the way im learning a lot from your code.:idea:
 

Re: Im learning Re: Mikrobasic and 4 7-segment displays

Hello,

I read through your explanation and after making the proper arrangements in the code, now it works. it was not hard. i forgot using PortB.7=1 individually doesnt function this way to turn on that 7-segment display on mikrobasic.

Glad to hear that! :smile:

Besides this, I have a couple of questions regarding your code for ADC. Where do you assign the bits for ADC conversion? How do you tell mikrobasic you want the ADC is 10-bits and not let's say 8-bit or less?

You don't: mikroBASIC always retrieves a 10-bit result (unless the ADC on the device has 8-bits resolution, eg 16F72).

If instead connecting the LM35 i want to put a potentiometer with its wiper tied to the analog input of the microcontroller and use it as a voltmeter. how do i change it so it can work that way? in other words, what if i want to make the displays show two decimals on the right side of the integer digit for example let's say a result of 3.12 Volts?

By the way im learning a lot from your code.:idea:

Before I explain this, I would like to know if you have previously used the ADC module.
 

Re: Im learning Re: Mikrobasic and 4 7-segment displays

Glad to hear that! :smile:



You don't: mikroBASIC always retrieves a 10-bit result (unless the ADC on the device has 8-bits resolution, eg 16F72).



Before I explain this, I would like to know if you have previously used the ADC module.

I used PicBasic Pro, in that language make it simple to select the ADC conversion bits from 8 to 10, i wasn't aware you can't do that in Mikrobasic.

Yes i have used that module but only from the examples through Mikrobasic tutorials besides i had read your blog entries as well, pretty interesting i have to say.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top