![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Sid2286
Joined: 12 Aug 2010 Posts: 119
|
working while in single step mode but not in normal mode |
Posted: Tue Sep 14, 2010 6:23 am |
|
|
wen i try to run this code during normal operation, it skips the while loop and enter the other function, however when i try with single stepping mode its working fine.
[/code]
#include <18F452.h>
#device ICD=TRUE ADC=10
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
int result;
void scan(); //key scan function declare
void display(int x); //display function declare
const char TABLE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0X82,0XF8,0X80,0X98};
#define char_P 0x8C
#define char_R 0xbb
#define char_O 0xA3
#define char_G 0x90
#define char_S 0x92
#define char_E 0x84
#define char_T 0x87
#define char_Z 0xbf
#define char_A 0x88
int i;
void init()
{
SET_TRIS_B(0XFF);
}
void prog()
{ delay_ms(10);
while(input(PIN_B0))
{
output_d(char_P);
output_low(PIN_A5);
delay_ms(1);
output_high(PIN_A5);
output_d(char_R);
output_low(PIN_A4);
delay_ms(1);
output_high(PIN_A4);
output_d(char_O);
output_low(PIN_A3);
delay_ms(1);
output_high(PIN_A3);;
output_d(char_G);
output_low(PIN_A2);
delay_ms(1);
output_high(PIN_A2);
}
}
void display_adc(int x)
{
while(input(PIN_B0))
{
int i,j,k,temp; //define four temporary variable
temp=x; //temporary keep AD convert result
i=temp/100; //get display hundred bit
j=(temp%100)/10; //get display ten bit
k=(temp%100)%10; //get display Entries bit
output_d(TABLE[i]); //get the display hundred bit code from table
output_low(PIN_A5);
delay_ms(1); //delay some time,ensure display brightness
output_high(PIN_A5);
output_d(TABLE[j]); //get the display ten bit code from table
output_low(PIN_A4); //RA4 OUTPUT low,light ten bit display
delay_ms(1); //delay some time,ensure display brightness
output_high(PIN_A4);
output_d(TABLE[k]); //get the display Entries bit code from table
output_low(PIN_A3); //RA5 OUTPUT low,light Entries bit display
delay_ms(1); //delay some time,ensure display brightness
output_high(PIN_A3);
}
prog();
}
void main()
{
float z;
init();
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
while(1)
{
set_adc_channel( 0 );
z = read_adc();
display_adc(z);
}
}
[/code]
ideally it should display the adc values on the segments and when Pin B0 is pressed it should go onto prog() but thats not happening :(
regards,
sid |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue Sep 14, 2010 7:12 am |
|
|
First, indent your code, and learn to use the code buttons. This will help you see errors, and us to read the code...
Then, you _must_ pause to let the ADC internal capacitor charge after selecting an ADC channel. Otherwise the result will be wrong. read the data sheet, and search the forum on this.
Then, you don't tell us how the button is wired. The 'standard' would be pull up resistors, and a button pulling the pin to ground. If so, then 'input(PIN_B0)' will be true when the button is _not_ pressed.
Then, you have the same button test on the entry to the display_adc function, and the prog function. If one is meant to execute when the button is pressed, and the other when it isn't, one of these is reversed.
As a 'comment', switch back to the old 'C' style, and put your variable declarations at the start of the function, rather than in the internal block. The latter is legal, but CCS is less than forgiving, and sometimes is more prone to giving problems if such constructs are used. Just 'safer'.
Then, you have the adc, set to return a 10bit value, but are using integers to hold the values in the code. An 'int' in CCS, is only 8bits. You need to be using an int16 here.
Read the data sheet. Is ADC_CLOCK_INTERNAL recommended for 20MHz operation?....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|