#define H_PATTERN_SIZE 16
#define V_PATTERN_SIZE 18
#define H_PSIZE 16
#define V_PSIZE 18
void MyDrawColoredPattern (void *info, CGContextRef myContext)
{
CGFloat subunit = 5; // the pattern cell itself is 16 by 18
CGRect myRect1 = {{0,0}, {subunit, subunit}},
myRect2 = {{subunit, subunit}, {subunit, subunit}},
myRect3 = {{0,subunit}, {subunit, subunit}},
myRect4 = {{subunit,0}, {subunit, subunit}};
CGContextSetRGBFillColor (myContext, 0, 0, 1, 1);
CGContextFillRect (myContext, myRect1);
CGContextSetRGBFillColor (myContext, 0, 0.5, .4, 1);
CGContextFillRect (myContext, myRect2);
CGContextSetRGBFillColor (myContext, 0, 1, 0, 1);
CGContextFillRect (myContext, myRect3);
CGContextSetRGBFillColor (myContext, .5, 0, 1.5, 1);
CGContextFillRect (myContext, myRect4);
}
void MyColoredPatternPainting (CGContextRef myContext,
CGRect rect)
{
CGPatternRef pattern;// 1
CGColorSpaceRef patternSpace;// 2
CGFloat alpha = 1,// 3
width, height;// 4
staticconst CGPatternCallbacks callbacks = {0, // 5
&MyDrawColoredPattern,
NULL};
CGContextSaveGState (myContext);
// CGContextTranslateCTM(myContext, rect.origin.x, rect.origin.y);
// CGContextTranslateCTM(myContext, 0, rect.size.height);
// CGContextScaleCTM(myContext, 1.0, -1.0);
// CGContextTranslateCTM(myContext, -rect.origin.x, -rect.origin.y);
patternSpace = CGColorSpaceCreatePattern (NULL);// 6
CGContextSetFillColorSpace (myContext, patternSpace);// 7
CGColorSpaceRelease (patternSpace);// 8
pattern = CGPatternCreate (NULL, // 9
CGRectMake (0, 0, H_PSIZE, V_PSIZE),// 10
CGAffineTransformMake (1, 0, 0, 1, 0, 0),// 11
H_PATTERN_SIZE, // 12
V_PATTERN_SIZE, // 13
kCGPatternTilingConstantSpacing,// 14
true, // 15
&callbacks);// 16
CGContextSetFillPattern (myContext, pattern, &alpha);// 17
CGPatternRelease (pattern);// 18
CGContextFillRect (myContext, rect);// 19
CGContextRestoreGState (myContext);
}
//文件 p33timer3.h #ifndef _P33TIMER3_H_ #define _P33TIMER3_H_ //#include "p33timer3.h" #define TIMER3_IEN_ENB _T3IE = 1 #define TIMER3_IEN_DIS _T3IE = 0 //timer3输入时钟分频 #define TIMER3_DIV1 (0<<4) #define TIMER3_DIV8 (1<<4) #define TIMER3_DIV64 (2<<4) #define TIMER3_DIV256 (3<<4) //============================= extern void Init_Timer3(uint16 T3div,uint16 Tcon) ; #endif //文件 p33timer3.c #include "global.h" #include "p33timer3.h" //*************************************** // 函数名称:Init_Timer3 // 函数功能:初始化timer3 // 入口参数:时钟分频系数 定时器计数个数 // 出口参数:无 // 返回值:无 // Timer3 的时钟源 = Fp(即外设时钟) //*************************************** void Init_Timer3(uint16 T3div,uint16 Tcon) { T3CON = 0X0000|T3div ; PR3 = Tcon ; //重装载寄存器 TMR3 = 0x0000 ; //计数器清0 _T3IF = 0 ; _T3IE = 0 ; T3CON |= (1<<15) ; //开启定时器3 } //应用实例 void main(void) { //-----Timer3----------------------------------- //外设时钟64分频到时钟 计数7197次 Init_Timer3(TIMER3_DIV64,7197) ;//T3时钟源为外设时钟Fp TIMER3_IEN_ENB ;//开启定时器中断 // TIMER3_IEN_DIS ; while(1) { } }
//文件 p33timer5.h #ifndef _P33TIMER5_H_ #define _P33TIMER5_H_ //#include "p33timer5.h" #define TIMER5_IEN_ENB _T5IE = 1 #define TIMER5_IEN_DIS _T5IE = 0 //timer3输入时钟分频 #define TIMER5_DIV1 (0<<4) #define TIMER5_DIV8 (1<<4) #define TIMER5_DIV64 (2<<4) #define TIMER5_DIV256 (3<<4) //============================= extern void Init_Timer5(uint16 T5div,uint16 Tcon) ; #endif //文件 p33timer5.c #include "global.h" #include "p33timer5.h" //*************************************** // 函数名称:Init_Timer5 // 函数功能:初始化timer5 // 入口参数:时钟分频系数 定时器计数个数 // 出口参数:无 // 返回值:无 // Timer5 的时钟源 = Fp(即外设时钟) //*************************************** void Init_Timer5(uint16 T5div,uint16 Tcon) { T5CON = 0X0000|T5div ; PR5 = Tcon ; //重装载寄存器 TMR5 = 0x0000 ; //计数器清0 _T5IF = 0 ; _T5IE = 0 ; T5CON |= (1<<15) ; //开启定时器5 } //应用实例 void main(void) { //-----Timer5----------------------------------- //外设时钟64分频到时钟 计数7197次 Init_Timer5(TIMER5_DIV64,7197) ;//T5时钟源为外设时钟Fp TIMER5_IEN_ENB ;//开启定时器中断 // TIMER5_IEN_DIS ; while(1) { } }