View Full Version : Thắc mắc CCS C , nhờ giúp đỡ !
Hieu98DT
27-04-2010, 09:13 PM
Chào mọi người !
Xin vui lòng giúp mình cái đoạn khai báo sau có nghĩa gì vậy ?
static bit CH_OUT @ BITNUM (PORTA,0) ;
static bit T_CH_OUT @ BITNUM (TRISA,0);
Chân thành cám ơn rất nhiều!
nhanh0112
29-04-2010, 11:26 AM
@Hieu98DT
Hình như code của bạn lấy 1 phần từ avr thì phải
Theo tui biết thì CCS đâu có khai báo đc biến kiểu bit (true/false)
@HAI1817
output_b(DIGITS[DIGIT] ^ 0xff);
Xuất ra port b giá trị 8 bit trong đó:
DIGITS[DIGIT] là biến mảng (array[x])
đc xor với 0xff (array[x] xor 0xff)
http://en.wikipedia.org/wiki/XOR_gate
Hieu98DT
01-05-2010, 09:59 PM
Code của mình từ đây ra nè bạn!
Mình đang tự học và thắc mắc ở đoạn code trên. Nhưng chắc các cao thủ chỉ trả lời những câu hỏi cao siêu thôi, nên câu hỏi của mình đến giờ vẫn bỏ xó.Đành tự tìm hiểu tiếp thôi.
Dù sao cũng cám ơn bạn đã trả lời.
#define _VERSION_ "V0.0.2"
/************************************************** **********************
* phase84.c
*
* Simple Phase control using PIC16F84 - 100% C Program.
* Using even time slicing method for both Triac and IGBT Drive methods.
* Just change specific #define to choose which method is in use.
*
* Output pin for phase ctrl is RA0
* Zero Cross input is RB0
* Remainder of PORTB is used for level setting 0 to 255 in incs of 2
*
* Output is Active LOW - i.e. it is desigend to pull an LEDs Cathode in an
* opto-coupler low to turn the output ON.
*
* Output Driver Types:
* Either TRIAC or IGBT control can be used with this software by selecting
* the appropiate #define command.
*
* IGBT Driver:
* An IGBT driver turns the output ON at the zero cross point and turns
* the output OFF part way through the cycle - this has really low
* EMI properties and is one of the few methods allowed for phase control
* in European countrys (i.e complies with EN55015 EMI standard).
* Other countries are following suit for example New Zealand and Austrailia
* are almost there (See AS/NZS 4051 and CISPR15 EMI Standards )
* This method of dimming is audibly quiet, does not require extra filter
* componets (If designed properly).It also has a better lamp life and can
* control a wider range of lamps than the TRIAC method of dimming.
*
* TRIAC Driver:
* A TRIAC driver turns the output OFF at the zero-cross and turns the
* output ON part way through the cycle - this has high EMI output and needs
* filter inducors etc. This has been the most popular method of phase
* control since it was first demonstraited in London in 1962. To make
* the TRIAC dimmer complient with modern EMI standards it requires
* carefully designed filter circuits using large Toroid Inductors
* and mains voltage AC rated capacitors.
* This is still the simplest method to do, and quite cheap, but not
* recommended for comercial designs any more.
* It also has a tendancy to reduce Lamp life, and creates alot of audiable
* noise in both the inductors and lamps.
*
*
*
* Processor: PIC16F84 @ 10Mhz
*
* Author: Michael Pearce
*
* Copyright 2001 Michael Pearce
* All Rights Reserved
*
* Free to use for non-comercial, non-profit personal use only.
* For Commercial use please contact author (He doesnt Bite) at
*
* mimemike@paradise.net.nz or mike@lightneasy.com
*
* Started: 10 July 2001 (My 20 something Birthday)
*
************************************************** ***********************
* Version Information
************************************************** ***********************
* Version 0.0.1 - 10 July 2001
* Changed Port Pins to match the circuit diagram.
* Made Input type selectable by #define (Switches or 8bit mode)
* UNTESTED!!!
* 98 Words ROM (IGBT Output + Switch Input Version)
* 99 Words ROM (IGBT Output + 8bit Input Version)
* 91 Words ROM (TRIAC Output + Switch Input Version)
* 92 Words ROM (TRIAC Ouptut + 8 bit Input Version)
************************************************** ***********************
* Version 0.0.1 - 10 July 2001
* Change User Input to an up and DOWN Key on 10ms Interrupt
* Test as Functional
* 98 Words ROM
************************************************** ***********************
* Version 0.0.0 - 10 July 2001
* First Draft of the Project
* Tested as functional
* 79 words of ROM
************************************************** ***********************/
#include <pic.h>
#define ON 0 /* To set Output to ON state */
#define OFF 1 /* To Set Output to OFF state */
/*** Select output settings - Choose only one from each ***/
/** Output Control Method **/
#define TRIAC /* TRIAC Control Turns ON part way through cycle */
//#define IGBT /* IGBT Control turnd OFF part way through cycle */
/** Mains Frequency **/
//#define HZ60 /* For 60Hz Mains system */
#define HZ50 /* For 50Hz Maind system */
/*** Select Input Mode - Switches or 8 BIT ***/
#define INPUT_SWITCHES /* Use UP/DOWN Switches */
//#define INPUT_8BIT /* Use 8 Bit I/O port */
/*********** Reload value for Phase Control ************************
* ((1/(MainsFreq*2)) / 256) / (1/(Crystal Freq/4)) = TimerCount
* For 50Hz Mains @ 10Mhz Clock For 60Hz @ 10MHz Clock
* 1/(50Hz*2) = 10ms 1/(60Hz*2) = 8.3ms
* 10ms/256 = 39us 8.3ms/256 = 32us
* 1/(10MHz/4) = 0.4us 1/(10MHz/4) = 0.4us
* 39us/0.4us = 97 32us/0.4us = 80
*
* Subtract Interrupt time and other delays (Guessing at around 5)
* For 50Hz: 97 - 5 = 93 For 60Hz: 80 - 5 = 75
*
* Reload @ 50Hz = -93 or 163 Reload @ 60Hz = -75 or 181
* (Counter counts up and resets at Zero)
* NOTE: These allow a MAXIMUM num of intstruction cycles between
* interrupts of 93 for 50Hz System, or 75 for 60Hz System.
************************************************** *****************/
#ifdef HZ50
#define TIMER_RELOAD 163
#endif
#ifdef HZ60
#define TIMER_RELOAD 181
#endif
/**** I/O Ports ****/
#ifndef BITNUM
#define BITNUM(adr, bit) ((unsigned)(&adr)*8+(bit)) /* used for port defs*/
#endif
static bit CH_OUT @ BITNUM(PORTA,0); /* Phase Ctrl Output PIN */
static bit T_CH_OUT @ BITNUM(TRISA,0); /* Tris for above */
static bit ZERO_INT @ BITNUM(PORTB,0); /* Zero Cross Interrupt PIN*/
static bit T_ZERO_INT @ BITNUM(TRISB,0); /* Tris for above */
static bit SW_UP @ BITNUM(PORTA,1); /* Increase Power Switch */
static bit T_SW_UP @ BITNUM(TRISA,1); /* Tris for above */
static bit SW_DWN @ BITNUM(PORTA,2); /* Decrease Power Switch */
static bit T_SW_DWN @ BITNUM(TRISA,2); /* Tris for above */
#define D_IN PORTB /* Data Input port */
static bit D_IN_LSB @ BITNUM(PORTA,3); /* LSB For data input PORT */
static bit T_DIN_LSB @ BITNUM(TRISA,3); /* TRIS for above */
/**** Global Variables ****/
unsigned char CH_COUNT; /* Interrupt Counter */
unsigned char CH_LEVEL; /* Target Level */
bit INT_10MS; /* 10ms interrupt flag */
/************************************************** *******************
* main
************************************************** *******************/
void main(void)
{
/***** Set Up OPTION ******
* RB Pullup = Enabled = 0
* IntEdge = Rise = 1
* T0 Src = Internal= 0
* T0 Edge = L to H = 0
* Prescale = WDT = 1
* Prescale = 1:1 = 000
***************************/
OPTION=0b01001000;
/**** Set up Ports ****/
TRISA=0xFF; /* Port A as Inputs */
TRISB=0xFF; /* Port B as Inputs */
T_CH_OUT=1; /* Output Pin to High Impedance State */
CH_OUT=0; /* When Tris set to Output, pull LOW */
T_ZERO_INT=1; /* Zero Cross Interrupt Pin as INPUT */
ZERO_INT=1;
SW_UP=1; /* Switch as INPUT */
T_SW_UP=1;
SW_DWN=1; /* Switch as INPUT */
T_SW_DWN=1;
/**** Initialise Variables ****/
CH_COUNT=0; /* Set Inital output to 0% */
CH_LEVEL=0;
INT_10MS=0; /* Dont check keys till interrupt */
/**** Set Up Interrupts ****/
INTCON=0x00; /* Disable All Interrupts and clear flags */
INTE=1; /* Enable ZeroCross Interrupt */
/* Note: T0IE enable from Zero Cross Routine */
GIE=1; /* Enable Global interrupts */
/**** Main Program Loop ****/
/* Loop FOREVER */
while(1)
{
/* Check for 10ms interrupt */
if(INT_10MS)
{
INT_10MS=0; /* Clear Flag */
/* If using UP/Down Switches */
#ifdef INPUT_SWITCHES
if(SW_UP==0)CH_LEVEL++; /* Check for INCREASE Switch */
if(SW_DWN==0)CH_LEVEL--; /* Check for DECREASE Switch */
#endif
/* If using 8-bit port */
#ifdef INPUT_8BIT
CH_LEVEL=D_IN &0xFE; /* Read in all except LSB */
if(D_IN_LSB)CH_LEVEL |=0x01; /* Read in LSB */
#endif
}
}
}
/************** END OF main *******************/
/************************************************** *********************
nhanh0112
02-05-2010, 12:15 AM
Chào mọi người !
Xin vui lòng giúp mình cái đoạn khai báo sau có nghĩa gì vậy ?
static bit CH_OUT @ BITNUM (PORTA,0) ;
static bit T_CH_OUT @ BITNUM (TRISA,0);
Chân thành cám ơn rất nhiều!
Vậy là chương trình của bạn đc định nghĩa bởi đoạn này
/**** I/O Ports ****/
#ifndef BITNUM
#define BITNUM(adr, bit) ((unsigned)(&adr)*8+(bit)) /* used for port defs*/
#endif
-----
ví dụ:
port A có địa chỉ là 5
địa chỉ của PIN_A0 là 40
chiếu với định nghĩa trên ta có: add*8+bit = 5*8+0=40
static bit CH_OUT @ BITNUM(PORTA,0); => CH_OUT đc gán bằng portA bit 0 (RA0)
CH_OUT=1 => RA0=1
CH_OUT=0 => RA0=0
Mà đoạn code trên của bạn đúng là ko phải của CCS (ht-pic thì phải)
Hieu98DT
03-05-2010, 01:34 PM
Cám ơn nhanh0112 nhiều lắm nha ! Thật ra mình đang tìm hiểu giải thuật của chương trình trên thôi.Mình cũng ko biết là của trình dịch nào nữa, vì tìm được trên mạng. Mình đang muốn làm bài tập nhỏ lập trình điều khiển đèn bằng triac, nhưng ko biết giải thuật nên đang tự ngâm cứu cái chương trình trên.Rất mong nhận được sự giúp đỡ của bạn
namqn
03-05-2010, 02:41 PM
Cám ơn nhanh0112 nhiều lắm nha ! Thật ra mình đang tìm hiểu giải thuật của chương trình trên thôi.Mình cũng ko biết là của trình dịch nào nữa, vì tìm được trên mạng. Mình đang muốn làm bài tập nhỏ lập trình điều khiển đèn bằng triac, nhưng ko biết giải thuật nên đang tự ngâm cứu cái chương trình trên.Rất mong nhận được sự giúp đỡ của bạn
Tôi cho là chương trình mà bạn đang tìm hiểu có xuất xứ từ đây:
http://www.microchipc.com/sourcecode/#triac
Nếu đúng vậy thì tác giả đã ghi rõ là họ dùng Hi-Tech PICC. Để hiểu cú pháp của các câu lệnh mà bạn đang thắc mắc, hãy đọc tài liệu hướng dẫn của Hi-Tech PICC (phiên bản dành cho PIC10/PIC12/PIC16).
Thân,
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.