CCS PCW = PİC C COMPİLER ÖRNEK PROGRAMLAR

1980best

Üye
Katılım
1 Ağu 2006
Mesajlar
18
Puanları
1
Yaş
39
////////////////////PİC18F252 İLE YAPILMIŞ BUTONA BAS LED YANSIN/////////////////

///////////////////////ALIN SİZE TÜRKÇE KAYNAK İŞTE////////////////////////

#include <18F252.h>
#use delay(clock=40000000)
#fuses H4,NOWDT,NOPROTECT,NOLVP,PUT,
#use rs232(baud=500000, xmit=PIN_C6, rcv=PIN_C7)

#BYTE PORTA = 0xF80
#BYTE PORTB = 0xF81
#byte PORTC = 0xF82

//******************************************************************************
#BIT RA0 = PORTA.0
#BIT RA1 = PORTA.1
#BIT RA2 = PORTA.2
#BIT RA3 = PORTA.3
#BIT RA4 = PORTA.4
#BIT RA5 = PORTA.5
//******************************************************************************
#BIT RB0 = PORTB.0
#BIT RB1 = PORTB.1
#BIT RB2 = PORTB.2
#BIT RB3 = PORTB.3
#BIT RB4 = PORTB.4
#BIT RB5 = PORTB.5
#BIT RB6 = PORTB.6
#BIT RB7 = PORTB.7
//******************************************************************************

INT TUR;


void main()
{
SET_TRIS_A(0);
SET_TRIS_B(0);
SET_TRIS_C(0);

RB0=1; /////////
RB1=1;/////////////
RB2=1;/////////////
RB3=1;//////////////
RB4=1;/////////////// RB X UÇLARI BİR BUTONLA ŞASEYE BAĞLI : BUTONA BASILIRSA RBX SIFIR OLUR LED YANAR
RB5=1;/////////
RB6=1;//////
RB7=1;////

RC0=0;
RC1=0;
RC2=0;
RC3=0;
RC4=0;
RC5=0;// BUZZER BAGLI
RC6=0;
RC7=0;

RD0=1;// LED BAĞLI
RD1=1;//LED
RD2=1;// LED
RD3=1;//LED
RD4=1;//LED
RD5=1; //LED
RD6=1;//LED
RD7=1;//LED


while (1)
{
IF (!RB1) {RD7=0; RC5=1;}
IF (!RB2) {RD7=0; RD6=0; RC5=1;}
IF (!RB3) {RD7=0; RD6=0; RD5=0; RC5=1;}
IF (!RB4) {RD7=0; RD6=0; RD5=0; RD4=0; RC5=1;}
IF (!RB5) {RD7=0; RD6=0; RD5=0; RD4=0; RD3=0; RC5=1;}
IF (!RB6) {RD7=0; RD6=0; RD5=0; RD4=0; RD3=0; RD2=0; RC5=1;}
IF (!RB7) {RD7=0; RD6=0; RD5=0; RD4=0; RD3=0; RD2=0; RD1=0; RC5=1;}
IF ((RB1)&&(RB2)&&(RB3)&&(RB4)&&(RB5)&&(RB6)&&(RB7)) {RD7=1; RD6=1; RD5=1; RD4=1; RD3=1; RD2=1; RD1=1; RC5=0;}
RD0=0;
delay_ms(100);
RD0=1;
delay_ms(100);
}

}

// RB LERİN UCU ŞASEYE BUTONLA BAğLI YANİ BUTONA BASINCA RB UçLARINDAN BİRİ SIFIR OLUYOR VE DİğER BACAKTAKİ LED YANIYOR.....VB
 
tesekkurler ornek icin... acaba bunların icinde 16f84 icinyazılmıs ornek varmıdır?
 
kardeş bunu hangi program ile çalıştıra biliriz yani pic'e hangi program ile atabilirz?
 
bende usb Programlama var WinPic 3.55 ile çalışan Pıc c Compiler yazdığım yazılımları bir türlü programlayamıyorum programlama kartımı hazır aldım elektronikçiden elektronikçiye geri götürdüm kart çalıştı bana yazılımında hata var dedi bende o gündr Winpic 3.55 i desdekleyen yazılım programı bulamıyorum bilgisi olan benimle paylaşırsa çok sevinirim şimdiden tşk ederim....
 
ben PIC16F877 ENTEGRESİ VE PCF8583(SAAT VE TARİH İÇİN ENTEGRE),LM35 ISI SENSÖRÜ İE TARİH SAAT VE SICAKLIĞI LCD EKRANDA GÖSTERMEK İSTİYORUM..
BUNUNLA İLGİLİ BİR PROGRAMA SAHİBİM AMA BENİM PROGRAMIMDA SICAKLIĞI GAYET İYİ GÖSTERİYOR SICAKLIKTA SORUN YOK.. AMA TARİH VE SAAT SABİT BİR ŞEKİLDE KALIYOR İLERLEMİYOR
MESELA SAAAT 12:10:09 BİR TÜRLÜ 12:10:10 OLMUYOR SABİT KALIYOR BEN MİCROC PRO FOR PİC PROGRAMIYLA YAZILMIŞ BİR PROGRAM...
PROTEUSDA SİMULASYON YAPTIĞIM ZAMAN DEVAMLI SAAT KONUSUNDA SORUN YAŞIYORUM...BEN DEVREMDE KULLANDIĞIM MALZEMELERİ,PROTEUSDA ÇİZİLMİŞ DEVREMİ VE PROGRAMIMI
ATACAĞIM YARDIMCI OLURSANZ ÇOK SEVİNİRİM...BUNU YAPAMAZSAM DERSTEN KALACAĞIM
KULLANDIĞIM MALZEMELE: Materials: RS232 İLETİŞİM KABLOSU,PIC16F877 ENTEGRESİ,LCD 2*16 EKRAN,LM35 SICAKLIK SENSÖRÜ,12 volt AC/DC Adaptor,ButtonLAR,
4 pieces 10k resistance,3 pieces 560 resistance,2 pieces 22 Pf capacitor,
5 PARÇA 1 mf KONDANSATÖR,2 PARÇA 100 mf KONDANSATÖR ,3 pARÇA 100 nf KONDANSATÖR,1 PARÇA 25 pf KONDANSATÖR,Max232 ENTERGRESİ,7805 ENTEGRESİ,
1 pARÇA 9 PİNLİ CONNECTOR,1 PARÇA KRYSTAL KONDANSATÖR 25-40 MHZ ARASI,1 PARÇA PERTİNAX,
10K LIK POTANSİYOMETRE(POTANSİYOMETRE İLE 2 MİLİSANİYELİK GECİKTİRME YAPRAK 2 TANE LEDİMİN YANIP SÖNMESİNİ SAĞLIYORUM)


MİCROC PRO FOR PİC C KODUM:

#define uchar unsigned char
// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
//output definitions
#define backlight PORTC.F0
#define sistemled portb.f1
#define outled portc.f2
//buttons definitions
#define btnEnter porte.f2
#define btnEsc porta.f2
#define btnUp porte.f0
#define btnDown porta.f4
#define btnLeft porta.f5
#define btnRight porte.f1
//
uchar seconds = 0;
uchar minutes = 0;
uchar hours = 0;
uchar day = 0;
uchar month = 0;
uchar year = 0;

uchar gorev=0;
// fonksiyon prototipleri
void initial();
void Read_Time();
void Transform_Time();
void Display_Time();
void clockprogramming();
void timetask();
void temperaturetask();
void menufunc();
void sicaklikoku(unsigned char kanal,unsigned char* dizi);
//fonksiyon prototipleri sonu

void main() {
initial();
while(1){
switch (gorev){
case 1: timetask();break;
case 2: temperaturetask();Delay_Ms(250);break;
//case 3: break;
default: ;
}
if(!btnEnter) menufunc();



} // main while

} // void main

void initial(){

PORTA=0;
TRISA=0xff;
ADCON0=0xa0; // Configure AN pins porta.f0,f1 analog;porta.f3 analog; diğerleri dijital
ADCON1=0x85; //
PORTB = 0;
TRISB = 0;
PORTC=0;
TRISC=0X80;
PORTD=0;
TRISD=0;
PORTE=0;
TRISE=7;
I2C1_Init(100000); // initialize I2C communication
UART1_Init(9600); // Initialize UART module at 9600 bps
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
backlight=1;
Lcd_Out(1,1,"merhaba");
sistemled=1;
outled=1;
clockprogramming();
OPTION_REG=0;
INTCON=0X90;
}
//--------------------- Reads time and date information from RTC (PCF8583)
void interrupt(){
if(intcon.intf){
intcon.intf=0;
gorev=1;
sistemled=~sistemled;
/*
Read_Time();
Transform_Time();
Display_Time();
*/
}


}// interrupt
/////////////////////////////
void menufunc(){
gorev=2;
Lcd_Out(1,3,"TEMPERATURE");

}
////////////////////////////
void Read_Time() {

I2C1_Start(); // Issue start signal
I2C1_Wr(0xA0); // Address PCF8583, see PCF8583 datasheet
I2C1_Wr(2); // Start from address 2
I2C1_Start(); // Issue repeated start signal
I2C1_Wr(0xA1); // Address PCF8583 for reading R/W=1

seconds = I2C1_Rd(1); // Read seconds byte
minutes = I2C1_Rd(1); // Read minutes byte
hours = I2C1_Rd(1); // Read hours byte
day = I2C1_Rd(1); // Read year/day byte
month = I2C1_Rd(0); // Read weekday/month byte
I2C1_Stop(); // Issue stop signal

}

//-------------------- Formats date and time
void Transform_Time() {
seconds = ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F); // Transform seconds
minutes = ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F); // Transform months
hours = ((hours & 0xF0) >> 4)*10 + (hours & 0x0F); // Transform hours
year = (day & 0xC0) >> 6; // Transform year
day = ((day & 0x30) >> 4)*10 + (day & 0x0F); // Transform day
month = ((month & 0x10) >> 4)*10 + (month & 0x0F); // Transform month
}

//-------------------- Output values to LCD
void Display_Time() {

Lcd_Chr(1, 6, (day / 10) + 48); // Print tens digit of day variable
Lcd_Chr(1, 7, (day % 10) + 48); // Print oness digit of day variable
Lcd_Chr(1, 9, (month / 10) + 48);
Lcd_Chr(1,10, (month % 10) + 48);
Lcd_Chr(1,15, year + 56); // Print year vaiable + 8 (start from year 2008)

Lcd_Chr(2, 6, (hours / 10) + 48);
Lcd_Chr(2, 7, (hours % 10) + 48);
Lcd_Chr(2, 9, (minutes / 10) + 48);
Lcd_Chr(2,10, (minutes % 10) + 48);
Lcd_Chr(2,12, (seconds / 10) + 48);
Lcd_Chr(2,13, (seconds % 10) + 48);
}
/////////////////////////////////////////
void clockprogramming(){

I2C1_Start(); // Issue start signal
I2C1_Wr(0xA0); // Address PCF8583, see PCF8583 datasheet
I2C1_Wr(0); // Start from address 0 (configuration memory location)
I2C1_Wr(0x80); // Write 0x80 to configuration memory location (pause counter...)
I2C1_Wr(0); // Write 0 to cents memory location
I2C1_Wr(0); // Write 0 to seconds memory location
I2C1_Wr(0x30); // Write 0x30 to minutes memory location
I2C1_Wr(0x12); // Write 0x12 to hours memory location
I2C1_Wr(0x24); // Write 0x24 to year/date memory location
I2C1_Wr(0x08); // Write 0x08 to weekday/month memory location
I2C1_Stop(); // Issue stop signal

I2C1_Start(); // Issue start signal
I2C1_Wr(0xA0); // Address PCF8530
I2C1_Wr(0); // Start from address 0
I2C1_Wr(0); // Write 0 to configuration memory location (enable counting)
I2C1_Stop(); // Issue stop signal
} //
//////////

void menufunc(){
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,5,"MENU");
Lcd_Out(2,1,"1: Mod Sel");
}
void timetask(){
Read_Time();
Transform_Time();
Display_Time();
}
////////////////
float adimbuyuklugu=5/1023;
unsigned long temperature=0;
unsigned int sicaklik=0;
unsigned int isi=0;
unsigned char isidegeri[16];
unsigned char setdegeri[16];
unsigned int isideger=0;
unsigned int setdeger=0;
unsigned char offset=20;
//////////////
void temperaturetask(){
unsigned char temp=0;
isideger=setdeger=0;
sicaklikoku(0,isidegeri);
sicaklikoku(1,setdegeri);
if(outled==1)if(isideger<=(setdeger-(unsigned int)offset))outled=0;
if(outled==0) {if(isideger>=setdeger)outled=1;}

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"Set : ");Lcd_Out_Cp(setdegeri);
Lcd_Out(2,1,"Temp: ");Lcd_Out_Cp(isidegeri);
}

void sicaklikoku(unsigned char kanal,unsigned char* dizi){
uchar i=0;
sicaklik=ADC_Read(kanal);
for(i=0;i<11;i++){
sicaklik += ADC_Read(kanal);
sicaklik=sicaklik/2;
}

if(kanal==0) {temperature = (long)sicaklik*1000;}
else if(kanal==1){ temperature = (long)sicaklik*100;}
temperature=(temperature/1023)*5;
sicaklik = (unsigned int)temperature;
if(kanal==0)isideger=sicaklik;else setdeger=sicaklik;
// sicaklik = 4999;
isi = sicaklik/1000;
if(isi==0) dizi[0]=32;else dizi[0]=48+isi;

isi = sicaklik-(isi*1000);
isi = isi/100;
if(isi==0){ if(dizi[0]==32)dizi[1]=32;else dizi[1]=48;}
else if(isi>0){dizi[1]=48+isi;}

sicaklik = sicaklik%100;
isi = sicaklik/10;
dizi[2]=48+isi;dizi[3]='.';

isi=sicaklik%10;
dizi[4]=48+isi;dizi[5]=0;

}//
//////////////////////


proteus devrem bu linkte

saat tarih sıcaklık - Windows Live
 
CCS ile PCW aynı program dillerimi?
 

Forum istatistikleri

Konular
128,108
Mesajlar
915,037
Kullanıcılar
449,808
Son üye
YunusKibar

Yeni konular

Geri
Üst