₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,346,238 members, 8,521,911 topics. Date: Friday, 20 November 2026 at 09:18 AM

Toggle theme

Princejude's Posts

Nairaland Forum › Princejude's Profile › Princejude's Posts

1 2 3 4 5 6 7 8 ... 14 15 16 17 18 19 20 (of 20 pages)

Programming › Re: Microcontrollers by princejude(m): 4:04am On May 14, 2013
Example 4: Moving LEDs

This is another simple LED example that will ON eight LEDs sequentially(one at a time). The LEDs were connected to PORTB


#include <16f887.h>
#fuses xt, nowdt, noprotect, noput
#use delay (clock = 4000000)

void main()
{
int n; //declare n as an integer variable
while(1) // loop forever
{
output_B(0x01 << n); // ON the 1st LED and SHIFT LEFT to the next one
n++; //increase the value of n
if(n>7) //is n greater than 7 ?
n = 0; //if yes, set n equal to zero
delay_ms(400); //wait 400 ms to slow down the speed
}
}


Programming › Re: Microcontrollers by princejude(m): 3:40am On May 14, 2013
Programming › Re: Microcontrollers by princejude(m): 6:29am On May 13, 2013
usisky: I think d above eqaution is a bit 'SUSPECT'. Given an ADC resolution of 10 bits , an upper and lower input voltage range of 5V and 0V. The equation should b:

Vin(temp)= (((VREFP-VREFM)/1024) *conversion_result*scaling_factor) - VREFM.

where ; VREFP--- positive refrence voltage(5V in dis case).

VREFM--- negative voltage reference(0V in dis case).

conversion result(adc value).

scaling factor(the factor by which u scaled ur input voltage i.e if u scale ur input by 100, den u multiply it by dis factor to obtain correct result).

while ur equation above will give seemingly d correct result, it wil however be off by at least 1LSB(of d ADC resolution). This is because u devided by 1023 intead of 1024. It may not appear to b a problem in such application(temperature sensing). However, when dealing with signals with narrow differential input voltages, dis wil b unacceptable.
welldone for ur input, we want more contribution to this thread, let it not be one man show because am a bit busy with other programming stuffs like FPGA, ARM and PSoC
Programming › Re: Microcontrollers by princejude(m): 3:11pm On May 12, 2013
cogitoErgo: I adjusted VR2 on the development board and that actually calibrated the temperature reading! But please Princejude, how did they get that conversion formular (i.e, temp=5.00*temp_adc*100.00/1023.00)?
That formula was used to convert the ADC value to temperature in degree Celcius

Note that the ADC module was configured to 10 bits (#device ADC=10) 10 bits = 210 = 1024 but you are counting from zero,0 to 1023
Programming › Re: Microcontrollers by princejude(m): 2:34pm On May 12, 2013
cogitoErgo: I don wait tire fo ur reply
Sorry for late reply, I was busy with office work.

cogitoErgo: The only problem is that the temperature reading Im getting is obviously wrong, instead of say 38 to 40 deg C, Im getting 199 to 200 deg C!
Check this second line of your code:


#include <16f887.h>
#device ADC=10 /*** If your #device ADC=8 (8 is default value and is for 8 bits)
It will give you wrong values
Change it to #device ADC=10 --- for 10 bits ****/

Programming › Re: Microcontrollers by princejude(m): 10:26pm On May 11, 2013
To transfer your hex file(compiled ccs code)to your MCU, you will need the following:
1. PIC Programmer (i.e, Pickit2 or Pickit3 or ICD2 or any)Note: Pickit2 (cloned) N5500 and Pickit3 N7000
If you are using pickit2 or pikit3, install its software in your PC.
2. PIC Development kit with PI16F887
3. And of course a computer system.

I have explained how to program an MCU in my earlier post in this thread. Check from first page.
Programming › Re: Microcontrollers by princejude(m): 11:45am On May 06, 2013
cogitoErgo:
 setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports(sAN0);
set_adc_channel(0); //read anal
lcd_init();


the 2nd line declares pin AN0 of d MCU as d analouge input pin[b](i really dnt kno what dat small s is fo!).[/b]
Hello CogitoErgo, Have you installed the CCS C Compiler in your PC? If yes, open the 16f887.h file from the installation location: C/Program Files/PICC/Devices then scroll down to ADC Function setups, you will see the ADC registers definition as shown below:


// Constants used in SETUP_ADC_PORTS() are:
// First argument:
// OR together desired pins
#define sAN0 1 //| A0
#define sAN1 2 //| A1
#define sAN2 4 //| A2
#define sAN3 8 //| A3
#define sAN4 16 //| A5
#define sAN5 32 //| E0
#define sAN6 64 //| E1
#define sAN7 128 //| E2
#define sAN8 0x10000 //| B2
#define sAN9 0x20000 //| B3
#define sAN10 0x40000 //| B1
#define sAN11 0x80000 //| B4
#define sAN12 0x100000 //| B0
#define sAN13 0x200000 //| B5
#define NO_ANALOGS 0 // None
#define ALL_ANALOG 0x1F00FF // A0 A1 A2 A3 A5 E0 E1 E2 B0 B1 B2 B3 B4 B5


thats where the small 's' is from. Note that NOT ALL PIC MCUs use the small 's'.

For example the ADC register definition for 16F877A is below


// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS 7 // None
#define ALL_ANALOG 0 // A0 A1 A2 A3 A5 E0 E1 E2
#define AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_VREF 1 // A0 A1 A2 A5 E0 E1 E2 VRefh=A3
#define AN0_AN1_AN2_AN3_AN4 2 // A0 A1 A2 A3 A5
#define AN0_AN1_AN2_AN4_VSS_VREF 3 // A0 A1 A2 A4 VRefh=A3
#define AN0_AN1_AN3 4 // A0 A1 A3
#define AN0_AN1_VSS_VREF 5 // A0 A1 VRefh=A3
#define AN0_AN1_AN4_AN5_AN6_AN7_VREF_VREF 0x08 // A0 A1 A5 E0 E1 E2 VRefh=A3 VRefl=A2
#define AN0_AN1_AN2_AN3_AN4_AN5 0x09 // A0 A1 A2 A3 A5 E0
#define AN0_AN1_AN2_AN4_AN5_VSS_VREF 0x0A // A0 A1 A2 A5 E0 VRefh=A3
#define AN0_AN1_AN4_AN5_VREF_VREF 0x0B // A0 A1 A5 E0 VRefh=A3 VRefl=A2
#define AN0_AN1_AN4_VREF_VREF 0x0C // A0 A1 A4 VRefh=A3 VRefl=A2
#define AN0_AN1_VREF_VREF 0x0D // A0 A1 VRefh=A3 VRefl=A2
#define AN0 0x0E // A0


So is important to look at the header file of any chip before you can use its ADC module
Programming › Re: Microcontrollers by princejude(m): 8:41am On Apr 29, 2013
cogitoErgo: NOLVP => I really could not get this!
NOLVP => NO Low Voltage Programming

Well done
Programming › Re: Microcontrollers by princejude(m):
cogitoErgo: Thanks for the manual. I think what remains for me is to get the PIC development kit!
When you are ready for the PIC development kit, check this link http://www.jutronix.com
They have good development kits with user manual which include many sample codes for beginners.
https://i35.tinypic.com/2vula9j.jpg
Programming › Re: Microcontrollers by princejude(m): 11:42am On Apr 22, 2013
cogitoErgo: OK, @princejude, from my findings on the net, integer variable in ccs c is a little different frm traditional c language! the normal int will declare a 8-bit integer, int16 will declare a 16-bit integer while int32 will do fo 32 bit integer!
You can also declare 8-bit interger as int8 in ccs c

Example of some data types are:


Data types Unsigned
int1 0 or 1
int8 0 to 255
int16 0 to 65535
int32 0 to 4294967295


You can download this ccs c user manual for more info:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Programming › Re: Microcontrollers by princejude(m): 1:55pm On Apr 15, 2013
hopefullman: ...d code is jst lyk chinese 2me.i jst wish 2 be lyk u.
Did you download the two ebooks I posted their links ? if yes, study them and you will understand the trick
Programming › Re: Microcontrollers by princejude(m):
.
Programming › Re: Microcontrollers by princejude(m): 2:11pm On Apr 09, 2013
hoodboi: Hw did u knw how to work wit d sensor nd oda components
I will always study there datasheets.

hoodboi: hw did u knw d level to set for d battery
I used the internal Analog to Digital Converter module of the chip to sense the battery level ans also used a variable resistor to calibrate the battery level.
Programming › Re: Microcontrollers by princejude(m): 2:01pm On Apr 09, 2013
NeoTesla: @princejude: Nice work. Very readable code. BTW how did you ensure the blocks were indented. The last time I tried to indent code on nairaland I was unsucessful.
Use the code icon labelled "#"

Before you type the code you want to post,Click the "#" icon and type the code between
 and 
.

[.code]

type your
code here

[./code]
Science/Technology › Re: Cost Of Different Sources Of Electricity In Nigeria by princejude(m): 3:26pm On Apr 08, 2013
Barcholder: Correction - Solar power is used both as grid tied, hybrid, and Stand alone systems. The batteries are easily charged by the Solar Panels, as long as its properly sized. Everything is accounted for, believe that.
Solar panel (with its charge controller) is just a battery charger. You cannot use it alone without a battery. And battery is always GIGO(Garbage-In-Garbage-Out) in other word,you can never take more than what you put inside the battery.
Science/Technology › Re: Cost Of Different Sources Of Electricity In Nigeria by princejude(m): 1:39pm On Apr 08, 2013
cheddarking: A house has 7 bedrooms and 2 living rooms....as well as a BQ comprising 1room/livingroom/toilet

The main house has 2 Large Fridges and 2 Deep Freezers.

Each bedroom has a Wall mounted 1hp AC...while the 2 living rooms have a 3HP split standing unit each.

There are 9 Flatscreen LEDs in this house, usually on at the same time.

There is also a pumping machine in the yard for water.


Can you use Solar Energy to Power this house? And how big is the Array gonna be?
Yes you can use solar energy to power the house but the cost of the solar energy materials and installation for the house can build the same house in another plot of land
Science/Technology › Re: Cost Of Different Sources Of Electricity In Nigeria by princejude(m): 1:19pm On Apr 08, 2013
Barcholder: Hi All

I'd like to start a discussion about the cost of Electricity in Nigeria today. The numbers make for interesting reading. And as they say, numbers don't lie.

Diesel Generator 71.7 Naira per kWh
Petrol Generator 69.5 Naira per kWh
PHCN Grid Electricity 23 Naira per kWh
Solar Power 15.5 Naira per kWh

Why on earth do Nigerians still persist on using generators?

Discuss
From your post above,Solar Power looks cheaper but I will like you to note the following points:

1. Solar Power system is made up of: the solar panels/cells (convert the solar energy to electrical energy(DC voltage/current)),solar charge controller (Regulates the converted DC voltage used to charge batteries), DC batteries (used to power up a UPS/Inverter), UPS/Inverter (converts the DC voltage from batteries to 230V AC voltage which you can use to power up your house)

2. Solar power is NOT normally used as a stand-alone power supply. It is used to support an existing power supply such as mains/PHCN or generator. The reason is that the power from solar system depends on the battery current and it will be difficult to fully charge the batteries from the solar panels (unless you have enough millions of naira to waste on panels). For your batteries to last longer, you will need to charge the batteries through Mains(PHCN) or generator.


thats my 2cent
Programming › Re: Microcontrollers by princejude(m): 11:34am On Apr 08, 2013
princejude: Exercise 3 : Servo motor control.
In this exercise, I will copy some sections of my code in a recent project titled "Automated waste bin". This is a simple wast bin with some automatic controls. The waste bin have an ultrasonic sensor, if you come close to the bin, the bin's door will open and ones you are through and out from the bin, the door will close. The opening and closing of the door was controlled using a servo motor while your distance from the bin was measured using an ultrasonic sensor.


Chei !! i don go late ooo ... will be back shortly
Yeah am back...
Here is the code for the servo motor control:


#include <16F887.h>
#device adc=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=cool

#define TRIG PIN_B2 // HC-SR04 Ultrasonic trig pin connected to MCU's pin B2
#define ECHO PIN_B1 // HC-SR04 Ultrasonic echo pin connected to MCU's pin B1
#define SERVO PIN_C3 // Servo motor connected to MCU's pin C3
#define LOW_BAT PIN_A1 // Low battery indicator connected to pin A1
#define FULL PIN_A2 // Waste bin FULL indicator connected to pin A2
#define RX PIN_B3 // Photo transistor(used to detect when waste-bin is full)
// is connected to pin B3

int16 distance, time, adc_res; // declare some variables as int16

void pulse_clockwise() // function to turn servo motor clockwise
{
output_high(SERVO);
delay_us(1445);
output_low(SERVO);
delay_ms(20);
}

void pulse_anticlockwise() // function to turn servo motor anticlockwise
{
output_high(SERVO);
delay_us(1530);
output_low(SERVO);
delay_ms(20);
}

void stop_pulse() // function to stop servo motor
{
output_high(SERVO);
delay_us(1480);
output_low(SERVO);
delay_ms(20);
}

void open_bin() // funtion to open the waste-bin
{
int8 i;
for(i=0;i<8;i++) // turns servo motor clockwise eight times
{
pulse_clockwise();
delay_ms(50);
stop_pulse();
delay_ms(400);
}
}

void close_bin() // function to close waste-bin
{
int8 j;
for(j=0;j<8;j++) // turns servo motor anticlockwise eight times
{
pulse_anticlockwise();
delay_ms(50);
stop_pulse();
delay_ms(400);
}
}

int16 get_distance() // gets your distance from the waste-bin(using HC-SR04
// Ultrasonic sensor
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); // initiating timer
{
output_high(TRIG); // ping the sonar
delay_us(20); // sending 20us pulse
output_low(TRIG);
while(!input(ECHO)) // wait for high state of echo pin
{}
set_timer1(0); // setting timer zero
while(input(ECHO)) // Wait for high state of echo pin
{}
time=get_timer1(); // Getting the time
distance=time*0.028 + 1.093 ; // Calculating the distance
return (distance); // returns the value of distance
}
}

void get_adc() // Sense the battery level using the internal
// ADC(Analog to Digital Converter) module of
// the microcontroller
{
delay_ms(50); // wait for ADC to initialize
adc_res = read_adc(); // Reads the adc result
if(adc_res < 200)output_high(LOW_BAT); // If the ADC result is below 200,
// ON the low battery indicator
else output_low(LOW_BAT); // if not,OFF the low bat indicator
}

void main() // main program starts here
{
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
set_adc_channel(0); // Selects adc channel 0
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!

stop_pulse(); // Stop servo motor
output_low(SERVO);
output_low(FULL);
output_low(LOW_BAT);
stop_pulse();

while(true)
{
if(input(RX)){output_high(FULL);} // if waste-bin full,ON ful indicator
else {output_low(FULL);} // else OFF indicator
get_adc(); // gets adc-value(battery level)
get_distance(); // gets your distance from the waste-bin
if(distance < 30) // if your distance to the bin is less than 30cm
{
open_bin(); // Open waste-bin
stop_pulse();
delay_ms(5000); // waits 5 second for you to dispose your waste
close_bin(); // Close waste-bin
stop_pulse();
}
else
{
stop_pulse(); // Stop servo motor
}
}
}
Programming › Re: Microcontrollers by princejude(m): 9:57am On Apr 08, 2013
cogitoErgo: Please why is everybody not talking again, where is Princejude and co?
I was busy,will try to upload some today
Programming › Re: Microcontrollers by princejude(m): 9:33am On Apr 08, 2013
hopefullman: @princjud.pls is it 2ru dt basic is more simpler than C?can i get a link 2learn Basic.thank u
Basic may be more simpler but you will get more online resources/tutorials on C. if you want to learn basic check mikroBasic at mikroElectronika. http://www.mikroe.com/mikrobasic/pic/
Programming › Re: Microcontrollers by princejude(m): 8:01am On Apr 04, 2013
hoodboi: hi princejude, thank you so much for ur efforts, it is highly appreciated. I want to ask, is there any book in pdf format you can upload to teach programming micro controllers. i downloaded a mplab compiler recently and i now have the proteus simulator. Also, pls among the exercises, can you include one to control the to and fro movement of a motor. thanx
Exercise 3 : Servo motor control.
In this exercise, I will copy some sections of my code in a recent project titled "Automated waste bin". This is a simple wast bin with some automatic controls. The waste bin have an ultrasonic sensor, if you come close to the bin, the bin's door will open and ones you are through and out from the bin, the door will close. The opening and closing of the door was controlled using a servo motor while your distance from the bin was measured using an ultrasonic sensor.


Chei !! i don go late ooo ... will be back shortly
Programming › Re: Microcontrollers by princejude(m):
cogitoErgo: I wuld like to have an automatic weather station dat culd datalog, etc!
That will be a nice project

cogitoErgo: i will like help on how to get some of d hardwares!
You will get most of the hardware at www.jutronix.com
Programming › Re: Microcontrollers by princejude(m): 7:53am On Apr 01, 2013
Programming › Re: Microcontrollers by princejude(m): 7:37am On Apr 01, 2013
hopefullman: thank u.must i av 2learn asm b4 learnin c?
No. You can learn C without asm.

hopefullman: i ws tld dt asm wl let me undstand d pic 4beta resourc alocatn.
Asm will help you to be familiar with the PIC registers because you use the register names directly in asm though in my own opinion it was a bit difficult to remember all the mnemonics. I prefer C to Asm because C is more friendly (like human language)

hopefullman: i dnt wnt 2spend so much tym on a lang dt wunt realy benefit me much.2nks
All programming languages are ok,and none is better than the other,what you achieved using C you can also achieve it using asm. The major issue is which of the language will be easier to learn.
Programming › Re: Microcontrollers by princejude(m): 7:07am On Apr 01, 2013
Use Google to search for free ebooks on PIC C programming. You can search with the following key words:

"ccs c ebook", "PIC C programming ebooks", "pic c programming pdf"

If you can download the book in the link below,you are good to go(It is for CCS C ) http://www.4shared.com/office/GzmYwLCl/Embedded_C_Programming__Microc.html
Programming › Re: Microcontrollers by princejude(m): 6:28am On Apr 01, 2013
hopefullman: i cuddnt find pic c tutorials on d net.all i see is sum pic projects in c lang wich i dnt understand.i avnt even find BASIC lang tutorials.pls if u hav a link 2 pic c tutorials pls kindly share.2nk u
There are many C compilers (with enough online resources)for PIC.
1. CCS C www.ccsinfo.com/forum Register with this forum ask questions and also search for sample codes in there code library.
2. MikroC PRO for PIC www.mikroe.com They have some good online ebooks which you can read free from here http://www.mikroe.com/pic/books/ This is there ebook on C: http://www.mikroe.com/products/view/285/book-pic-microcontrollers-programming-in-c/ You can also download there compiler here: http://www.mikroe.com/pic/compilers/
3. Hi-Tech C
Forum Games › Re: Spot The Soldier If You Can by princejude(m): 4:06am On Mar 31, 2013
kemesty: The soldier is in b1. Please how can I upload pics on nairaland?
Upload the pics to any free image hosting site such as tinypic.com. Then copy the image link and paste it in nairaland reply or new post.
Programming › Re: Microcontrollers by princejude(m): 10:16pm On Mar 30, 2013
http://www.hobbyprojects.com/pic_tutorials/tutorial1.html
The above link will be a good start for PIC assembly programming
Programming › Re: Microcontrollers by princejude(m): 9:36pm On Mar 30, 2013
hopefullman: I compild ds code and mplab told me build suced bt didnt display d hex file.hw wl i get d hex file.
The hex file will be inside your project folder. That is the folder where you saved the MPLAB project.
Programming › Re: Microcontrollers by princejude(m): 9:17pm On Mar 30, 2013
hopefullman: I compild ds code...
That is assembly language. Why not you start with basic or C language. C language will be easier to learn than assembly
Programming › Re: Embedded Systems by princejude(m): 8:29pm On Mar 12, 2013
usisky:

Also, if you need to work on Embedded Ethernet/Internet enabled devices, you may want to take a look at this chip from Microchip: ENC28j60. A sample app. can be found at here: AVRnet

That ENC28j60 is a powerful chip, You can get it in Naija at www.microscale-embedded.com
Programming › Re: Microcontrollers by princejude(m): 10:07am On Mar 11, 2013
hoodboi: I want to ask, is there any book in pdf format you can upload to teach programming micro controllers.
There is a lot of free microcontroller ebooks (pdf) online. Just google it and be specific on the type of microcontroller and compiler you want to learn'

hoodboi: Also, pls among the exercises, can you include one to control the to and fro movement of a motor. thanx
What type of motor do you want to control.... AC motor, DC motor, Stepper motor or Servo motor ?

1 2 3 4 5 6 7 8 ... 14 15 16 17 18 19 20 (of 20 pages)