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

Key hit start program

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
arelone



Joined: 06 Dec 2015
Posts: 42

View user's profile Send private message

Key hit start program
PostPosted: Mon Dec 05, 2016 4:45 pm     Reply with quote

Hi,

I have a simple program to start blinking LED when 'a' from the keyboard is pressed.The program has no errors but the program does not start even 'a' has been pressed. I am using Pic18F4580, ccs c compiler ver 5.010, crystal 20MHz, win 10. Can't resolve the problem.

TQ


Code:

#include <18F4580.h>
//#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

void main()
{

   
   while(true)
   {
     
    wait:
    while(!kbhit());
    if(getc()!='a')
    goto wait;
     
    output_low(PIN_B6);
    delay_ms(500);
    output_high(PIN_B6);
    delay_ms(500);
   }
   

}
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Dec 05, 2016 5:11 pm     Reply with quote

Code:

void main()
{

   
   while(true) {
 
    if (kbhit()) // {
        if (getc()=='a'){
         
         output_low(PIN_B6);
         delay_ms(500);
         output_high(PIN_B6);
         delay_ms(500);
    }// if getcc
   } // end kbhit
  } // end while tru
   
} // end main


how bout that ??


Last edited by asmboy on Mon Dec 05, 2016 6:38 pm; edited 1 time in total
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Dec 05, 2016 5:11 pm     Reply with quote

PLEASE don't let this be Proteus Isis ??
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Dec 05, 2016 5:41 pm     Reply with quote

first I'd need to KNOW the hardware is working so a 1Hz LED program needs to be cut/compiled/tested then...
some kind of
get data from PC, display on 'screen' program is next to do...

Aside from lots of WIN10 'issues', there's hardware issues like is this a REAL RS232 port or a USB<>TTL interface or ???

Also 'errors' MUST be added to the USE RS232(..options...)

'It doesn't work' can be broken down into 2 possibilites
1) bad hardware
2) bad software

#1 HAS to get fixed first....

Jay
arelone



Joined: 06 Dec 2015
Posts: 42

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 4:57 am     Reply with quote

Hi,

I tested the code given however the problem remains. I tested with the code below which reads from 8 adc channels via UART and display the values in hyper terminal and it is working accordingly. If there is compatibility issue, what compiler version compatible with win10?
I want to test the code by pressing the start switch connected to RB0. Any examples?

Code:

#include <18F4580.h>
#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define button (PIN_B0)

void main()
{
  setup_adc_ports(ALL_ANALOG); 
  setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_8);
   
  const int8 channel[] = 0, 1, 2, 3, 4, 5, 6, 7;
  int16 ADC_value[sizeof(channel)];
  int8 value;
  int16 voltage[sizeof(channel)];
  int z; 
 
 
  SETUP_ADC_PORTS(ALL_ANALOG);
  output_low(PIN_B6);
  output_low(PIN_B7);

  while(TRUE)
  {
    while(TRUE)
   {
     for(z = 0; z < 1; z++)
    {
      output_low(PIN_B6);

      // Collect all ADC data
      for(value = 0; value < sizeof(channel); value++)            // Read from 8 adc channels
      {
       
        set_adc_channel(channel[value]);
       
        ADC_value[value] = read_adc();  // ADC readings
        voltage[value] = ADC_value[value] * (5000 / 255);         // Convert ADC data to mV
        output_high(PIN_B7);
      }

      // Print all ADC data
      for(value = 0; value < sizeof(channel); value++)            // Display 8 voltage values
      {
        printf("%4.3w\r\n", voltage[value]);
      }

      printf("9\r\n");
    }
  }
}
}
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 6:14 am     Reply with quote

1st , all versions of compiler will work with Win10, though YOU have to tell WIN10 a few things, here and there, that's one reason I still use XP, I don't have the time to setup Win10.

2nd, CCS does supply LOTS of examples,yup..in the examples 'folder', and they DO have a 'press-a-button-do-something' program in there.

3rd.
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define button (PIN_B0)

you still must add 'errors' to #use rs232(...options....)
( ) around PIN_B0 doesn't look correct
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 11:29 am     Reply with quote

Have you ever proven that getc() works ? Try this simple rs-232 echo
program. See if you get back (on the terminal) the same key that you type.
Make sure you disable "local echo" in your terminal program for this test:
Code:

#include <18F4580.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20M)
#use rs232(baud=9600, UART1, ERRORS)

//===============================
void main()
{
int8 c;
   
while(TRUE)
  {
   c = getc();
   putc(c);
  }
 
}
arelone



Joined: 06 Dec 2015
Posts: 42

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 4:49 pm     Reply with quote

Hi,
Thanks for the reply. Can I know any links which can provide information on settings CCS in win10?

Tq
arelone



Joined: 06 Dec 2015
Posts: 42

View user's profile Send private message

PostPosted: Tue Dec 06, 2016 5:02 pm     Reply with quote

Hi,

I tested the rs-232 echo program and on the terminal display exactly the key I pressed. Any ideas what is exactly the problem?

TQ
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 06, 2016 7:08 pm     Reply with quote

First, disconnect the PIC from the PC and check you DO NOT get a echo back just to make sure local echo is turned off.

Then have a look at what input() does in the manual.
Using the code provided by PCM, make the echo come back only after pressing the button.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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