Input doesn't work in PIC controller.

AI Thread Summary
The user is experiencing issues with input not functioning correctly on a PIC microcontroller circuit designed in Proteus. The code is intended to trigger output on PORTB when a switch connected to RA0 is closed, but it only works when using digital pins instead of analog pins. The problem arises because the input pin RA0 is set as a weak high input, while the output LEDs are weak low outputs, indicating a potential configuration issue. To resolve this, it's suggested to configure the ADCON1 register to set all I/O pins to digital mode, which disables the analog-to-digital converters. Properly setting the ADCON1 register is crucial for ensuring the desired functionality of the circuit.
Zalajbeg
Messages
77
Reaction score
3
Hi everyone,

In the past I learned very good things about electronics and PIC controller in this forum. After that I have decided to design a circuit with a PIC micro-controller and simulated it in Proteus. However it doesn't work. Could you have a look and tell me what I am missing?

The circuit scheme is that:

Circuit.png


My code is below:

Code:
#include <pic.h>
#include <delay.c>
#include <stdio.h>
#define magnet RA0

int main(void)
{
	char n=1;
	unsigned int i;
	unsigned char birth[]={
		0x84, 0x84, 0xFD, 0x84, 0x84, 0x00,
		0x01, 0x02, 0xFC, 0x02, 0x01, 0x00,
		0x84, 0x84, 0xFD, 0x84, 0x84, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xFF, 0x18, 0x24, 0x42, 0x81, 0x00,
		0x84, 0x84, 0xFD, 0x84, 0x84, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0xFF, 0x81, 0x81, 0x42, 0x3C, 0x00,
		0x7E, 0x81, 0x81, 0x81, 0x7E, 0x00,
		0x79, 0x85, 0xA5, 0xA5, 0x69, 0x00,
		0xFF, 0x81, 0x81, 0x42, 0x3C, 0x00,
		0x7F, 0x80, 0x80, 0x80, 0x7F, 0x00,
		0xFF, 0x06, 0x18, 0x60, 0xFF, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00
		};
	unsigned char name[]={
		0x01, 0x02, 0xFC, 0x02, 0x01, 0x00,
		0x81, 0x81, 0xFF, 0x81, 0x81, 0x00,
		0xFF, 0x80, 0x80, 0x80, 0x80, 0x80,
		0xFF, 0x81, 0x81, 0x42, 0x3C, 0x00,
		0x81, 0x81, 0xFF, 0x81, 0x81, 0x00,
		0xC1, 0xA1, 0x99, 0x85, 0x83, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00
		};
		
		TRISA=0x01; TRISB=0;
		PORTA=0; PORTB=0;
		for(;;){
			while(n){
				if(magnet==1){
					for(i=0;i<112;i++){
						PORTB=birth[i];
						DelayMs(1000);
						}
				n=0;
					}
				}

		n=1;
			while(n){
				if(magnet==1){
					for(i=0;i<56;i++){
						PORTB=name[i];
						DelayMs(1000);
						}
				n=0;
					}
				}
		n=1;
		}
		}

I want to get output when I close the switch which gives input to RA0. If I delete this condition from my codes the circuit works. However I couldn't do this with an input. Could you explain me what is happening?

Edit: The input pin show as (WHI) Weak High Input. However the LEDs seems as (WLO) Weak Low Output.

Edit 2: When I use D pins instead of A pins it works perfect. However if you can explain why it doesn't work with A pins I will be happy to read.
 
Last edited:
Engineering news on Phys.org
You need to set the ADCON1 register to

adc.h: #define ADC_0ANA_0REF 0b00000111 // ALL DIGITAL I/O (0/0)

to shut off the analog->digital converters so you can use digital I/O.
(Actually, look ADCON1 up in the spec sheet to verify the bit settings,
I get confused by their attempt to make ORmasks work like ANDmasks
and vice versa...)

I believe, at least on the 18F2455 that I use, this will preclude using any ADCs
so you might want to select a higher A-bit as your input just in case.
 
Hi all I have some confusion about piezoelectrical sensors combination. If i have three acoustic piezoelectrical sensors (with same receive sensitivity in dB ref V/1uPa) placed at specific distance, these sensors receive acoustic signal from a sound source placed at far field distance (Plane Wave) and from broadside. I receive output of these sensors through individual preamplifiers, add them through hardware like summer circuit adder or in software after digitization and in this way got an...
I have recently moved into a new (rather ancient) house and had a few trips of my Residual Current breaker. I dug out my old Socket tester which tell me the three pins are correct. But then the Red warning light tells me my socket(s) fail the loop test. I never had this before but my last house had an overhead supply with no Earth from the company. The tester said "get this checked" and the man said the (high but not ridiculous) earth resistance was acceptable. I stuck a new copper earth...
I am not an electrical engineering student, but a lowly apprentice electrician. I learn both on the job and also take classes for my apprenticeship. I recently wired my first transformer and I understand that the neutral and ground are bonded together in the transformer or in the service. What I don't understand is, if the neutral is a current carrying conductor, which is then bonded to the ground conductor, why does current only flow back to its source and not on the ground path...

Similar threads

Replies
1
Views
2K
Replies
3
Views
2K
Replies
7
Views
4K
Back
Top