CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Need programming help of pic16f506
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 10, 2011 3:35 pm     Reply with quote

Download the data sheet for your PIC. Look at the pin diagram. The PIC
has pins on it. The pins have a number. They also have a name. One of
the pins is called "B1". OK ?

You absolutely MUST download the PIC data sheet and at least browse
through it. Here is the link again:
http://ww1.microchip.com/downloads/en/DeviceDoc/41268D.pdf

With regard to bitwise operators, we don't want to teach basic C.
You must research and read online tutorials. Use Google to find them.
Search for this:
Quote:

bitwise operators in C tutorials

Here are two of them. Search for more and read until you understand it.
http://www.eskimo.com/~scs/cclass/int/sx4ab.html
http://compsci.ca/v3/viewtopic.php?t=9893
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Mon Oct 10, 2011 3:43 pm     Reply with quote

i have already open the datasheet, of the pic..
probably you mean the RB1 as B1..ok..
B1 is number 12 pin..

check now again the diagram..


for number 1 the lcd needs pin 4 and pin 6 activated...
according to my diagram, these pins are connected to pin 7 and pin 8..
so how do i trigger the pin 7 and 8 of the pic??

before asking, for the bitwise, i had read some wikipedia's info, but i ll try the links that you recommended..
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Mon Oct 10, 2011 3:46 pm     Reply with quote

nikolas wrote:
what does the (PIN_B1) stand for?

also in the if statement, there is a bitwise and
so for example (itemp & 64 )
this should give
for instance itemp = 12

itemp => 00001100
64 => 01000000
this would give us
itemp & 64 01001100

so what do we actually check by if ( itemp & 64 ) if this is different from 0?
and if so what does the output_high(PIN_BIN1 would return..??

also the 3rd paragraph that you mention PCM programmer, when we have for instance neutral => 63 => 0011 11111
how will this be written in order our pic to give the right 1s in the pins..??
pintf? output_high(63) ?


that was my mistake, i wrote bitwise or

bitwise and would give us 00000000 in the example mentioned above..!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 10, 2011 4:33 pm     Reply with quote

I think Ttelmah has actually done it all for you, if you would just realize it.

Suppose you want to show that you are in 1st gear, then you just call
the routine that he made for you, like this:
Code:

display_digit(1);


Or you can use a variable:
Code:

void main()
{
int8 gear;

gear = 1;

display_digit(gear);

while(1);
}
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Mon Oct 10, 2011 5:53 pm     Reply with quote

PCM programmer wrote:
I think Ttelmah has actually done it all for you, if you would just realize it.


That is quite likely the case, as I have no clue of the integration of software and hardware when it comes to pinouts. I thought there should be a unique pinout line for each pin.
Sorry if I upset you or tire you guys, I try my best not to, but I can understand that i may sound tiring even with less than 15 posts so far.

Is there a freeware program that i can simulate, the code?
Since I'm still waiting the pic to arrive? (I was told it would take 10 days, that's why I'm trying to cover that time, by getting as close as possible to programming it)
I tried MikroC pro, but probably I'm making something wrong and the simulation doesn't work out as it should.
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 4:07 pm     Reply with quote

any ideas about a simulation program..??

(also, a compiled, and programmed pic, can accept modifications to its existing program? ) or is this some sort of package after compilation (like .exe) so that the program is no more editable..???
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 4:17 pm     Reply with quote

Just Google for it:
Quote:

7-segment simulator microchip

Example:
http://www.oshonsoft.com/pic.html

But don't ask us to make the simulator work for you. This is the CCS
compiler forum.
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 5:06 pm     Reply with quote

Thank you for the link,
I get some errors.

Code:
0 304 C:/Users/Public/Documents/Mikroelektronika/mikroC PRO for PIC/Examples/Development Systems/EasyPIC6/Led Blinking/potential.c:1: error: Can't open include file "16f506.h" 
0 304      #include <16F506.h> 
0 304 C:/Users/Public/Documents/Mikroelektronika/mikroC PRO for PIC/Examples/Development Systems/EasyPIC6/Led Blinking/potential.c:2: error: Unknown #directive "fuses" 
0 304      #fuses INTRC_IO, IOSC4, NOWDT 
0 304 C:/Users/Public/Documents/Mikroelektronika/mikroC PRO for PIC/Examples/Development Systems/EasyPIC6/Led Blinking/potential.c:3: error: Unknown #directive "use" 
0 304      #use delay(clock = 4M) 
0 304 C:/Users/Public/Documents/Mikroelektronika/mikroC PRO for PIC/Examples/Development Systems/EasyPIC6/Led Blinking/potential.c:4: error: Unknown #directive "use" 
0 304      #use rs232(baud=9600, xmit=PIN_C3) 
0 304 4 errors in preprocessor. 
0 304 C:/Users/Nikos/Desktop/ÍÝïò öÜêåëïò\vstrom/potentialcode.c:1: error: Can't open include file "16f506.h" 
0 304     #include <16F506.h> 
0 304 C:/Users/Nikos/Desktop/ÍÝïò öÜêåëïò\vstrom/potentialcode.c:2: error: Unknown #directive "fuses" 
0 304      #fuses INTRC_IO, IOSC4, NOWDT 
0 304 C:/Users/Nikos/Desktop/ÍÝïò öÜêåëïò\vstrom/potentialcode.c:3: error: Unknown #directive "use" 
0 304      #use delay(clock = 4M) 
0 304 C:/Users/Nikos/Desktop/ÍÝïò öÜêåëïò\vstrom/potentialcode.c:4: error: Unknown #directive "use" 
0 304      #use rs232(baud=9600, xmit=PIN_C3) 
0 304 4 errors in preprocessor. 
0 102 Finished (with errors): 13 Ïêô 2011, 02:04:08 potential.mcppi


any idea...??

missing some library perhaps...?? or incorrect include file?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 5:11 pm     Reply with quote

Apparently it (or you) is trying to compile CCS code with the MikroC
compiler. CCS code is not compatible with MikcroC.

Again, I don't want to provide Oshonsoft support, so I'm leaving the thread.
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 5:25 pm     Reply with quote

this error log, came from microC
but similar errors came from cc5x as well..
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 5:51 pm     Reply with quote

downloaded ccs as advised,
for the time being i get an error (not enough ram for all variables..)
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 6:08 pm     Reply with quote

a compilation of the code kindly supplied from PCM Programmer and Ttelmah

Code:
#include <16F506.h>
 #fuses INTRC_IO, IOSC4, NOWDT
 #use delay(clock = 4M)
 #use rs232(baud=9600, xmit=PIN_C3) 

 //===============================

 void display_digit(val);
 
 void main()
 {
 int8 result;
 setup_adc_ports(AN0_AN2); 
 setup_adc(ADC_CLOCK_DIV_8);
 set_adc_channel(0);
 delay_us(10);   

 while(1)
   {
    result = (read_adc())/26;
     
 //   printf("%u \n\r", result);
   display_digit(result); // this is not correct, i had to reduce the array, due to lack of memory, so i have to figure out a way so that result is expressed in a scale 0 to 6**
    delay_ms(500); 
   
   
   }
 }
 
 
 int8 dbits[7] = {63,12,91,94,108,118,119};

 void display_digit(int8 val) {
    int8 itemp;
    if (val>9) return; //Impossible to display
    itemp=dbits[val];
    if (itemp & 64) {
       //Here extra bit on B1 needs to go on
       output_high(PIN_B1);
    }
    else {
       output_low(PIN_B1); //else off
    }
    output_c(itemp & 63); //send other six bits;
 }



**for instance
if (result>240){ // 255 is for 5volts as PCM programmer figured)
temp=0 ;
display_digit(temp);
etc..
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 7:42 pm     Reply with quote

and sth more..
i choose microcontroller view, and i can see pins getting on..
but when i change pin13 value nothing changes..

i used, this part of code, just for check, but made no difference..


Code:
 while(1)
   {
    result = read_adc();
     
 //   printf("%u \n\r", result);
   if (result>240){  //neutral
   temp = 0;
   display_digit(temp);}
   else  if (result<40){ ///1st gear
   temp = 1;
   display_digit(temp);}
   else  if (result<80){ //2nd gear
   temp = 2;
   display_digit(temp);}
   else  if (result<120 ){ //3rd gear
   temp = 3;
   display_digit(temp);}
   else  if (result< 160 ){ //4th gear
   temp = 4;
   display_digit(temp);}
   else  if (result< 200 ){ //5th gear
   temp = 5;
   display_digit(temp);}
   else { //6th gear
   temp = 6;
   display_digit(temp);}
    delay_ms(1000); 
   
   }
 }


well, i guess PCM Programmer, might be able to help to define the values, according to the voltage..
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Thu Oct 13, 2011 6:17 am     Reply with quote

also, i don't know if this actually the reason, but i notice from the scratch of running the program that c3 pin is on, and only if the condition is for a number that doesn't involve c3, it goes out.. can this be settled somehow..?? omitted perhaps..??
#use rs232(baud=9600, xmit=PIN_C3)
nikolas



Joined: 09 Oct 2011
Posts: 32

View user's profile Send private message

PostPosted: Thu Oct 13, 2011 6:52 am     Reply with quote

i tried another simulator called

"real pic simulator"

i enter a sevent segment lcd, and an analog value to roll...
weird thing is that the analog allowed me to play from 0 to 1023...
so could it be 12bit?
also, rolling the values made the lcd, display the numbers,
also, there was an enable option at lcd, and i didn't know which one to choose, so i chose, vdd..but i guess this is not correct..
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group