View previous topic :: View next topic |
Author |
Message |
arelone
Joined: 06 Dec 2015 Posts: 42
|
Key hit start program |
Posted: Mon Dec 05, 2016 4:45 pm |
|
|
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);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Dec 05, 2016 5:11 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Dec 05, 2016 5:11 pm |
|
|
PLEASE don't let this be Proteus Isis ?? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Mon Dec 05, 2016 5:41 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
arelone
Joined: 06 Dec 2015 Posts: 42
|
|
Posted: Tue Dec 06, 2016 4:57 am |
|
|
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");
}
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Tue Dec 06, 2016 6:14 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 06, 2016 11:29 am |
|
|
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);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
arelone
Joined: 06 Dec 2015 Posts: 42
|
|
Posted: Tue Dec 06, 2016 4:49 pm |
|
|
Hi,
Thanks for the reply. Can I know any links which can provide information on settings CCS in win10?
Tq |
|
![](templates/subSilver/images/spacer.gif) |
arelone
Joined: 06 Dec 2015 Posts: 42
|
|
Posted: Tue Dec 06, 2016 5:02 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Tue Dec 06, 2016 7:08 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|