Let the future tell the truth and evaluate each one according to his work and accomplishments. The present is theirs; the future, for which I really worked, is mine. (Nikola Tesla)

15/05/2011

●Gauss Elimination Method using Matlab for Numerical Analysis

Here is the code to implement Gauss Elimination Method. The program asks for order of the system, coefficient matrix and right hand side vector. Then, it prints out the the augmented matrix after each forward elimination step and prints out the solutions after back substitution.


n=input('Order of the system= ');

A=input('Coefficient matrix= ');

B=input('Right hand vector= ');

X=input('Initial Estimate= ');

tol=input('Tolerance= ');

N=X;

for a=1:100

for i=1:n

z=0;

for t=1:i-1

z=z+(A(i,t)*X(t));

end

for t=i+1:n

z=z+(A(i,t)*X(t));

end

N(i)=X(i);

X(i)=(B(i)-z)/A(i,i);

end

X

if(abs((X(i)-N(i))/X(i))

end

end

20/02/2011

●Sending Data by Using PIC16F628A with Serial Communication

Here is the program written by using CCS C.


#include <16f628.h>
#fuses NOPROTECT, NOWDT, NOLVP, NOMCLR, INTRC_IO, XT
#use delay(clock=4M) //Be aware you set the same clock frequency for PIC
#use rs232(baud=9600 , xmit=PIN_B2) //Be aware you have the same baud rate for virtual terminal and use the B2 pin for transmitting the data

void main(){
while(1){
printf("Sezgin"); //Sending data as a string
delay_ms(250); //Setting the time for the delay
}
}



27/01/2011

●Serial Communication Using PIC16F628A

Serial communication refers to sending one bit data at a time on a line or a computer bus. It is used for long distance communications, especially computer networks where difficulties on cabling and synchronization makes parallel communication inconvenient.

While we're using PIC16F628A for serial communication, we use RS-232 standard. So, we need to know some terms as baud rate and some instructions used in CCS C for RS-232.

We define instructions for RS-232 in CCS C as below:
#use rs232 (...)

One of the definitions for RS-232 is the baud rate (baud=x). The baud rate is used to denote the number of bits transferred per second. We may define baud rate as different values like 9600.
Here is an table for RS232 cable length according to Texas Instruments:

Baud rateMaximum cable length (ft)
1920050
9600500
48001000
24003000


In our examples, we use 9600 as our baud rate. So we can define;
#use rs232 (baud=9600)

The other thing is the transmitting the data. We should specify the pin that we choose for transmitting the data (xmit=x). We are free to choose a pin. So we can define;
#use rs232 (xmit=PIN_B0)

The other thing is the receiving the data. We should specify the pin that we choose for receiving the data (rcv=x). We are free to choose a pin. So we can define;
#use rs232 (rcv=PIN_B2)

Parity is the another thing in RS232 communication (parity=x). We can define the parity as even(E), odd(O) or not(N). So we can define;
#use rs232 (parity=N)

Bits definition is another step in our rs232 definition (bits=x). While using software UART, CCS supports from 5 bits up to 9 bits. If we want to use two stop bits, we should define 9 bits and make the 9th bit as high. So we can define;
#use rs232 (bits=8)

For RS485 communication, we may use a intstruction (enable=x). So we can define;
#use rs232 (enable=PIN_B4)

Finally, we should regulate the virtual terminal operating properties compatible with the arranged values on our program. For instance on Proteus:





11/09/2010


●Displaying a Scrolling Script from Right to Left on 2x16 LCD

Here is the program written by using CCS C.


#include <16f628.h>
#fuses NOPROTECT, NOWDT, NOLVP, NOMCLR, INTRC_IO
#use delay(clock=4M)
#include

void main()
{

int a=32,x=16;

lcd_init(); //Must be called before any other function

for( ; ;x--,a--){

lcd_gotoxy(x,1);
lcd_putc("Sezgin Secil");
delay_ms(200);
lcd_putc("\f"); //To clear the display
if(a==0){ a=32,x=16; }

}
}


Note: lcd_gotoxy and lcd_putc are the functions that are presented by lcd.c file.

23/08/2010


●Displaying Constant Scripts on 2x16 LCD

Here is the program written by using CCS C.



#include <16f628.h>
#fuses NOPROTECT, NOWDT, NOLVP, NOMCLR, INTRC_IO
#use delay(clock=4M)
#include //It is essential for using LCD in our program

void main(){

lcd_init(); //Must be called before any other function
while(1){
lcd_gotoxy(1,2); //To set write position on LCD
lcd_putc("Sezgin Secil"); //Displaying script on the next position of the LCD
}
}



Note: For using LCD in our designs, we should use lcd.c file. It is used for both Port B and D. So, if we want to use it for Port B, we need a modification in the lcd.c file:
Find LCD.C file in drivers, open it, find the line that consists of "//define use_portb_lcd TRUE" and change that as "define use_portb_lcd TRUE". All you need to do is removing the the double slash at the beginning of the command.



15/08/2010


●Counting from 9 to 0 on 7-Segment Display

Here is the program written by using CCS C.



#include <16f628.h>
#fuses NOPROTECT, NOWDT, NOLVP, NOMCLR, INTRC_IO //Adding internal oscillator with INTRC_IO and MCLR makes possible to reset but with NOMCLR there is no need to connect anything that pin
#use delay(clock=4M) //To define the delay time correctly

void main(){
char series[]={63,6,91,79,102,109,125,7,127,111}; //Defining the decimal values of total logic values on 7-segment display
char x=9; //To start the loop from 9nd value
while(1){
do{
output_b(series[x]); //To show the desired value on 7-segment display
delay_ms(250); //Delay for observation
x--;
}while((x+1)); //To end the loop
x=9;
}
}



●Flashing LED Controlled by a Button

Here is the program written by using CCS C.


#include <16f628.h>
#fuses NOPROTECT, NOWDT, NOLVP, NOMCLR INTRC_IO //Adding internal oscillator with INTRC_IO and MCLR makes possible to reset but with NOMCLR there is no need to connect anything that pin
#use delay(clock=4M) //To define the delay time correctly

void main(){
while(1){ // For an endless loop
if(!input(pin_a0)) //Checking the input of the first pin of port A
output_high(pin_b0); //If input is low, LED flashes
else output_low(pin_b0); //If input is high, LED doesn't flash
}
}


ShareThis