Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Assembly language for PIC16F877A

mavis123

Newbie
Joined
Aug 22, 2023
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
20
I am a university student, currently I am taking the subject microprocessor and microcontroller systems. I have an assignment where we have to control the speed of the DC fan using microcontrollers. For this assignment Arduino is not allowed to use so we have to use assembly language but I am not familiar with the coding. There are three types of fan speed, one is if less than 25 degree Celsius the fan will stop, if the temperature is less than 28 degree Celsius the fan speed will be low, if the temperature is more than 28 degree Celsius the speed of the fan is high. I have to do coding between microcontroller PIC16F877A, L239D and a DC fan. Can anyone help me to code this, I have searched online for coding but all the coding is for Arduino.
circuit mic.jpeg
 
I'm guessing L239 is really an L293.

From the schematic it looks like you try to control the fan speed with PWM. It will work but depending on the fan you use, it may be difficult to set an exact speed, you should get some control though.
I would also warn you that the output of the LM35 is quite small so you would benefit from either amplifying it or using a lower ADC reference (an input to "VREF"). The resolution of the ADC if you use it as it is will be quite low.

Break the problem into small steps:
1. Forget the motor for now, concentrate on getting the temperature to the LCD.
2. Print something like "Hello Edaboard" on the LCD so you can check the routines for controlling the LCD. The LCD will be your debugging output so its important it works first. Check the data sheet for the LCD to see how to initialize it and the timing of the initializing bytes.
3. Move on to reading the temperature, you have to sets some bits in the ADC registers to configure it to use VDD as reference and RA0 as the input pin. Set then monitor the Go/-Done bit to wait for the reading to be taken. Remember the ADC returns a binary value representing the temperature but not the temperature itself so you need to do some multiplying to scale one to the other.
4. When you have the temperature being shown 'live' on the LCD, move on the motor control.
5. Read the data sheet to find out how to produce a PWM signal. PWM is generated in hardware so all you have to do is program the registers, the signal will be produced continuously by the PIC. You have to decide a PWM rate, resolution and what values are needed to set your fan speed. I would suggest a low PWM rate (~1KHz) and 8-bit resolution as the fan will be somewhat unpredictable anyway.
6. In a loop, read the LM35, compare it with the value for 28C and set either a low PWM duty cycle or a high one. You will have to experiment to find values suiting your particular fan.

You say you have to use assembly language, is this mandatory or can you use 'C' or another high level language?

Brian.
 
There is lots and lots of information on PIC assembly language on the microchip site.

First, you need to learn the language. Then, draw a flow chart or state machine or something else to help you visualize your task. I agree with Brian that you need to break this into steps.
 
I would also suggest you run simulations before testing in the hardware. That way you won’t find yourself with a bug and not know if it’s hardware or software.
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top