8051 7 Segment display program written in Basic

While browsing through the mikroelectronika website and looking at available downloads, I noticed their Basic compilers for various microcontroller architectures. So after downloading the 8051 version and installing lets look at an example converted from the C version.

The code is below, some key differences as you can see looking at the 2 code examples.

The comments are different, in Basic its While … Wend and you do not need a ; after every statement. In general though its simple to convert across, so if Basic is your preferred programming language then you could do worse than try this out, there is a free code size limited trial

C Code

void main()
{
do
{

P0 = 0xFF;
//activate segments 1 at a time
P0 = 0xF9;
Delay_ms(1000);
//number 2
P0 = 0xA4;
Delay_ms(1000);
//number 3
P0 = 0xB0;
Delay_ms(1000);
//number 4
P0 = 0x99;
Delay_ms(1000);
//number 5
P0 = 0x92;
Delay_ms(1000);
//number 6
P0 = 0x82;
Delay_ms(1000);
//number 7
P0 = 0xF8;
Delay_ms(1000);
//number 8
P0 = 0x80;
Delay_ms(1000);
//number 9
P0 = 0x98;
Delay_ms(1000);
//number 0
P0 = 0xC0;
Delay_ms(1000);
P0 = 0xff;

} while(1); // Endless loop
}

Basic Code

program LED_Blinking

main:
while TRUE
P0 = 0xFF
‘activate segments 1 at a time
P0 = 0xF9
Delay_ms(1000)
‘number 2
P0 = 0xA4
Delay_ms(1000)
‘number 3
P0 = 0xB0
Delay_ms(1000)
‘number 4
P0 = 0x99
Delay_ms(1000)
‘number 5
P0 = 0x92
Delay_ms(1000)
‘number 6
P0 = 0x82
Delay_ms(1000)
‘number 7
P0 = 0xF8
Delay_ms(1000)
‘number 8
P0 = 0x80
Delay_ms(1000)
‘number 9
P0 = 0x98
Delay_ms(1000)
‘number 0
P0 = 0xC0
Delay_ms(1000)
P0 = 0xff
wend ‘ Endless loop
end.

 

Links

for 8051

Related posts

8051 and RGB led example using the SiLabs IDE

C8051F340 flashing led example

8051 and 7 segment displays