View previous topic :: View next topic |
Author |
Message |
art
Joined: 21 May 2015 Posts: 181
|
Output D problem |
Posted: Fri Jan 22, 2016 2:58 am |
|
|
Hai, I'm having trouble when I type 12345678 result at output D only D4,D5,D6 and D7 become high, D1,D2,D3,D4 will become low. Suppose all Output D will become High. What cause this problem ?
Code: |
#include <18F4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <stdlib.h>
#include <input.c>
#include <string.h>
void main()
{
unsigned char x[9] ;
char a[] ="12345678";
unsigned char key;
unsigned char d;
while (TRUE)
{
if(d=='Z')
{
while (key!=32) // push SPACE BAR to stop
{
get_string(x,9);
if (strcmp(x,a)==0)
{
output_high(PIN_D0);
output_high(PIN_D1);
output_high(PIN_D2);
output_high(PIN_D3);
output_high(PIN_D4);
output_high(PIN_D5);
output_high(PIN_D6);
output_high(PIN_D7);
}
} key=0;
}
}
}
|
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jan 22, 2016 4:07 am |
|
|
How much of your while loop routine ever executes?
How do you know what the pin states are?
Have you tried setting all the portD pins to zero before the while loop?
Have you tested that all the portD pins can move?
Mike |
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Fri Jan 22, 2016 4:28 am |
|
|
Hi mike,
If i change all output D to output B the problem will not happen. It will only happen at output D. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jan 22, 2016 6:04 am |
|
|
Can you make portD work correctly by a different method?
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Fri Jan 22, 2016 6:25 am |
|
|
First thought was another peripheral is active on those pins but it is Odd that a nibble is not working. Perhaps it's a wiring problem. As the code 'worked on port B', I suspect hardware..maybe no power to those 4 LEDs?
Would need to see schematic and/or photo to help more.
A simple 1Hz LED program for all pins, as Mike says, might be useful.
Jay |
|
|
|