caramoan tour package

caramoan tour package

Author Topic: look-up table sa MikroC  (Read 386 times)

Offline tamuragko

  • CR2032 Battery
  • **
  • Posts: 21
  • Pogi/Ganda Points: 1
look-up table sa MikroC
« on: April 04, 2012, 07:17:23 AM »
Hi po mga master, i'm a newbie in high level PIC programming pero mai konting experience na po with assembly language...

Tanong ko lang po kung pano gumwa nang parang "look-up" table sa MikroC..  ;D ;D

Philippine Electronics Forum

look-up table sa MikroC
« on: April 04, 2012, 07:17:23 AM »

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4162
  • Pogi/Ganda Points: 166
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: look-up table sa MikroC
« Reply #1 on: April 04, 2012, 08:01:31 AM »
Hi po mga master, i'm a newbie in high level PIC programming pero mai konting experience na po with assembly language...

Tanong ko lang po kung pano gumwa nang parang "look-up" table sa MikroC..  ;D ;D

gamit ka ng switch-case or array....depende sa application

Code: [Select]
// convert hex to char
switch(hexnumber)
{
case 0:
  character = '0'
  break;
case 1:
  character = '1'
  break;
case 2:
  character = '2'
  break;
default:
  character = '0'
  break;
}

Code: [Select]
char lookup[4] = {'0','1','2','3'}; // initialize lookup table here.

// convert hex to char
character = lookup[hexnumber];
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Philippine Electronics Forum

Re: look-up table sa MikroC
« Reply #1 on: April 04, 2012, 08:01:31 AM »

Offline tamuragko

  • CR2032 Battery
  • **
  • Posts: 21
  • Pogi/Ganda Points: 1
Re: look-up table sa MikroC
« Reply #2 on: April 04, 2012, 12:24:52 PM »
yeah got it working... one other thing sir, pano pag fuctions na ilagay ko sa array...??? like
 

Code: [Select]

char lookup[2] = {funk1(),funk2()};


nag eerror na sya.

Philippine Electronics Forum

Re: look-up table sa MikroC
« Reply #2 on: April 04, 2012, 12:24:52 PM »

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4162
  • Pogi/Ganda Points: 166
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: look-up table sa MikroC
« Reply #3 on: April 04, 2012, 12:47:29 PM »
yeah got it working... one other thing sir, pano pag fuctions na ilagay ko sa array...??? like
 

Code: [Select]

char lookup[2] = {funk1(),funk2()};


nag eerror na sya.


use the switch-case,

switch(func_ref)
{
  case 0:
    function1();
    break;
  case 1:
    function2();
    break;
  default:
    break;
}
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Philippine Electronics Forum

Re: look-up table sa MikroC
« Reply #3 on: April 04, 2012, 12:47:29 PM »

Offline tamuragko

  • CR2032 Battery
  • **
  • Posts: 21
  • Pogi/Ganda Points: 1
Re: look-up table sa MikroC
« Reply #4 on: April 04, 2012, 06:12:38 PM »
cool.. thanks sir glutnix_neo :D

Philippine Electronics Forum

Re: look-up table sa MikroC
« Reply #4 on: April 04, 2012, 06:12:38 PM »

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4162
  • Pogi/Ganda Points: 166
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: look-up table sa MikroC
« Reply #5 on: April 04, 2012, 06:20:19 PM »
cool.. thanks sir glutnix_neo :D

common mistake lang sa switch case, malimit nakakalimutang lagyan ng break yung bawat case, dapat palaging may default din and define how to handle default....

default yung condition similar to else sa if-else statement...
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline carlsberg11

  • Lead Acid Battery
  • *******
  • Posts: 526
  • Pogi/Ganda Points: 30
  • Gender: Male
Re: look-up table sa MikroC
« Reply #6 on: April 26, 2012, 01:26:54 AM »
^UP.

sir question regarding lookup table. pwedi po ba i set mo yung output of any port you like sa pic?

example.

Code: [Select]
// convert hex to char
switch(hexnumber)
{
case 0:
  PORTB= 0xA8;
  Delay_ms(45.6);
  PORTB= 0xB1;
  break;
case 1:
  PORTB= 0x90;
  Delay_ms(45.6);
  PORTB= 0x00;
  break;
case 2:
  PORTB= 0x00;
  Delay_ms(45.6);
  PORTB= 0x12;
  break;
default:
  PORTB= 0xA2;
  Delay_ms(45.6);
  PORTB= 0x56;
  break;
}

valid po ba yung above code?
Anyone who has never made a mistakes has never tried anything new.

-Albert Einstein

Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: look-up table sa MikroC
« Reply #7 on: April 26, 2012, 05:25:10 AM »
^^ Hindi! ;D ;D
Mag error po yan.
Di pwedi decimal point sa delay_ms.
Use delay_us instead, i.e. delay_us(45600).
At tulad ng sabi ni master gluti na kailangan may break sa bawat case at meron din default.
 
The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Offline carlsberg11

  • Lead Acid Battery
  • *******
  • Posts: 526
  • Pogi/Ganda Points: 30
  • Gender: Male
Re: look-up table sa MikroC
« Reply #8 on: April 26, 2012, 11:11:27 AM »
^^ Hindi! ;D ;D
Mag error po yan.
Di pwedi decimal point sa delay_ms.
Use delay_us instead, i.e. delay_us(45600).
At tulad ng sabi ni master gluti na kailangan may break sa bawat case at meron din default.
 

yun salamat master lurker. para kasi to sa POV, :D :D ommit ko na lang yung decimal points regarding the delays. thanks for correction master! +1 :D 101+1
Anyone who has never made a mistakes has never tried anything new.

-Albert Einstein

Philippine Electronics Forum

Re: look-up table sa MikroC
« Reply #8 on: April 26, 2012, 11:11:27 AM »

 

Privacy Policy

Contact Us: elabph@yahoo.com