当前位置: 编程技术>移动开发
本页文章导读:
▪TextView惯用属性 TextView常用属性参考自《疯狂android讲义》2.3节
//TextView所呈现的文字
android:text="我爱Java"
//文字颜色
android:textColor="#f00"
//文字尺寸
android:textSize="20pt"
//文本框结尾处绘制图片
android:drawabl.........
▪ dsPIC33EP 快速PWM模块初始化设置及应用 dsPIC33EP 高速PWM模块初始化设置及应用//文件 p33pwm6.h
#ifndef _P33PWM6_H_
#define _P33PWM6_H_
//#include "p33pwm6.h"
#define FSYNCOEN (1<<8)//主时基同步使能位
#define FSYNCEN (1<<7)//外步时基同步使能.........
▪ dsPIC33EP timer1 初始化设立及应用 dsPIC33EP timer1 初始化设置及应用//文件 p33timer1.h
#ifndef _P33TIMER1_H_
#define _P33TIMER1_H_
//#include "p33timer1.h"
#define TIMER1_IEN_ENB _T1IE = 1
#define TIMER1_IEN_DIS _T1IE = 0
//timer1输入时钟分频
#define TIMER1_DIV1 .........
[1]TextView惯用属性
来源: 互联网 发布时间: 2014-02-18
TextView常用属性
bg_border.xml
bg_border2.xml
参考自《疯狂android讲义》2.3节
//TextView所呈现的文字
android:text="我爱Java"
//文字颜色
android:textColor="#f00"
//文字尺寸
android:textSize="20pt"
//文本框结尾处绘制图片
android:drawableEnd="@drawable/ic_launcher"
//不管内容多长,单行显示
android:singleLine="true"
//文字过长时,中间部分省略
android:ellipsize="middle"
//全部字母大写
android:textAllCaps="true"
//若文字为email或者电话号码,以特殊形式呈现
android:autoLink="email|phone"
//文字为密码,以点代替
android:password="true"
//文字阴影相关
android:shadowColor="#0000ff"
android:shadowDx="10.0"
android:shadowDy="8.0"
android:shadowRadius="3.0"
//指定背景图案
android:background="@drawable/bg_border"
实例一:TextView的常用属性
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!-- 设置字体为20pt,文本框结尾处绘制图片 --> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="我爱Java" android:textSize="20pt" android:drawableEnd="@drawable/ic_launcher" /> <!-- 设置中间省略, 所有字母大写 --> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:text="我爱Java我爱Java我爱Java我爱Java我爱Java我aaaJava" android:ellipsize="middle" android:textAllCaps="true" /> <!-- 对邮件、电话增加链接 --> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:text="邮件是kongyeeku@163.com,电话是02088888888" android:autoLink="email|phone" /> <!-- 设置文字颜色 、大小,并使用阴影 --> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="测试文字" android:shadowColor="#0000ff" android:shadowDx="10.0" android:shadowDy="8.0" android:shadowRadius="3.0" android:textColor="#f00" android:textSize="18pt" /> <!-- 测试密码框 --> <TextView android:id="@+id/passwd" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:password="true" /> <!-- 测试CheckedTextView 通过checkMark设置该文本框的勾选图标 --> <CheckedTextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="可勾选的文本" android:checkMark="@drawable/ok" /> </LinearLayout>
实例二:使用xml文件指定drawable资源,并用之于TextView的背景
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><!-- 通过android:background指定背景 --><TextViewandroid:layout_width="match_parent" android:layout_height="wrap_content"android:text="带边框的文本"android:textSize="24pt"android:background="@drawable/bg_border"/><!-- 通过android:drawableLeft绘制一张图片 --><TextView android:layout_width="match_parent"android:layout_height="wrap_content"android:text="圆角边框、渐变背景的文本"android:textSize="24pt"android:background="@drawable/bg_border2"/></LinearLayout>
bg_border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 设置背景色为透明色 -->
<solid android:color="#0000"/>
<!-- 设置红色边框 -->
<stroke android:width="4px" android:color="#f00" />
</shape>
bg_border2.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 指定圆角矩形的4个圆角的半径 -->
<corners android:topLeftRadius="20px"
android:topRightRadius="5px"
android:bottomRightRadius="20px"
android:bottomLeftRadius="5px"/>
<!-- 指定边框线条的宽度和颜色 -->
<stroke android:width="4px" android:color="#f0f" />
<!-- 指定使用渐变背景色,使用sweep类型的渐变
颜色从红色→绿色→蓝色 -->
<gradient android:startColor="#f00"
android:centerColor="#0f0"
android:endColor="#00f"
android:type="sweep"/>
</shape>
[2] dsPIC33EP 快速PWM模块初始化设置及应用
来源: 互联网 发布时间: 2014-02-18
dsPIC33EP 高速PWM模块初始化设置及应用
//文件 p33pwm6.h
#ifndef _P33PWM6_H_
#define _P33PWM6_H_
//#include "p33pwm6.h"
#define FSYNCOEN (1<<8)//主时基同步使能位
#define FSYNCEN (1<<7)//外步时基同步使能位
//输入时钟预分频选择
#define PWMCLK_DIV1 (0<<0)
#define PWMCLK_DIV2 (1<<0)
#define PWMCLK_DIV4 (2<<0)
#define PWMCLK_DIV8 (3<<0)
#define PWMCLK_DIV16 (4<<0)
#define PWMCLK_DIV32 (5<<0)
#define PWMCLK_DIV64 (6<<0)
#define V_PTPER 720//1000 //主控时基周期值
#define POH1_ValidH IOCON1 &= ~(1<<13) //上管引脚高电平有效
#define POH1_ValidL IOCON1 |= (1<<13) //上管引脚低电平有效
#define POH2_ValidH IOCON2 &= ~(1<<13) //上管引脚高电平有效
#define POH2_ValidL IOCON2 |= (1<<13) //上管引脚低电平有效
#define POH3_ValidH IOCON3 &= ~(1<<13) //上管引脚高电平有效
#define POH3_ValidL IOCON3 |= (1<<13) //上管引脚低电平有效
#define PWMAH_ENB IOCON1bits.OVRENH = 0
#define PWMBH_ENB IOCON2bits.OVRENH = 0
#define PWMCH_ENB IOCON3bits.OVRENH = 0
#define PWMAH_DIS IOCON1bits.OVRENH = 1
#define PWMBH_DIS IOCON2bits.OVRENH = 1
#define PWMCH_DIS IOCON3bits.OVRENH = 1
//===============================================
extern void Init_Pwm6(uint16 InClkdiv,uint16 CycPwm) ;
extern void ToPwmValue(uint16 Tcon) ;
#endif
//文件 p33pwm6.c
#include "global.h"
#include "p33pwm6.h"
//***************************************
// 函数名称:Init_Pwm6
// 函数功能:初始化PWM
// 入口参数:PWM时钟分频 PWM周期值
// 出口参数:无
// 返回值:无
// pwm 的时钟源为Fosc (即系统时钟)
//***************************************
void Init_Pwm6(uint16 InClkdiv,uint16 CycPwm)
{
PTCON = 0x0000 ; //PWM模块禁止 每次比较产生触发事件
PTCON2 = InClkdiv ; //输入时钟预分频
PTPER = CycPwm ; //主控周期值
PHASE1 = CycPwm ; //主移相寄存器
PHASE2 = CycPwm ;
PHASE3 = CycPwm ;
SEVTCMP = 0X0000 ; //特殊事件比较计数值位
CHOP = 0X0000 ; //斩波时钟发生器-- 禁止
MDC = 0x0000 ; //主控占空比值
PDC1 = 0x0000 ; //pwm占空比寄存器
PDC2 = 0x0000 ;
PDC3 = 0x0000 ;
/*
//PTPER 提供周期 mdc为PWM提供占空比
PWMCON1 = 0X0180 ; //禁止死区控制
PWMCON2 = 0X0180 ; //禁止死区控制
PWMCON3 = 0X0180 ; //禁止死区控制
*/
//PHASEx 提供周期 PDCx为PWM提供占空比
PWMCON1 = 0X0280 ; //禁止死区控制
PWMCON2 = 0X0280 ; //禁止死区控制
PWMCON3 = 0X0280 ; //禁止死区控制
/*
//PHASEx 提供周期 PDCx为PWM提供占空比
PWMCON1 = 0X0380 ; //禁止死区控制
PWMCON2 = 0X0380 ; //禁止死区控制
PWMCON3 = 0X0380 ; //禁止死区控制
*/
DTR1 = 0X0000 ; //死区寄存器
DTR2 = 0X0000 ;
DTR3 = 0X0000 ;
ALTDTR1 = 0X0000 ; //备用死区寄存器
ALTDTR2 = 0X0000 ;
ALTDTR3 = 0X0000 ;
TRGCON1 = 0X0000 ; //PWM触发控制寄存器
TRGCON2 = 0X0000 ;
TRGCON3 = 0X0000 ;
/*
PWM模块控制H管 GPIO控制L管
PWM IO引脚模式处于独立模式
*/
IOCON1 = 0X8c00 ; //PWM IO 控制寄存器
IOCON2 = 0X8c00 ;
IOCON3 = 0X8c00 ;
POH1_ValidH ; //上管引脚 高电平有效
POH2_ValidH ;
POH3_ValidH ;
TRIG1 = 0X0000 ;//PWM主触发比较值寄存器
TRIG2 = 0X0000 ;
TRIG3 = 0X0000 ;
//PWM故障限流控制寄存器 禁止限流 禁止故障输入
FCLCON1 = 0X0003 ;
FCLCON2 = 0X0003 ;
FCLCON3 = 0X0003 ;
LEBCON1 = 0X0000 ;//前沿消隐控制寄存器
LEBCON2 = 0X0000 ;
LEBCON3 = 0X0000 ;
LEBDLY1 = 0X0000 ; //前沿消隐延时寄存器 限流和故障输入消隐
LEBDLY2 = 0X0000 ;
LEBDLY3 = 0X0000 ;
AUXCON1 = 0X0000 ; //PWM附属控制寄存器
AUXCON2 = 0X0000 ;
AUXCON3 = 0X0000 ;
PTCON |= (FSYNCOEN|FSYNCEN) ;//主时基同步使能
//当PWM不使能时 PWMH PWML管脚输出的电平状态
//第1位为上管 第0位为下管
IOCON1bits.OVRDAT = 0X00 ; //PWM禁止时 PWMH PWML输出0
IOCON1bits.OVRDAT = 0X00 ; //
IOCON1bits.OVRDAT = 0X00 ; //
PWMCON1 |= 0X0001 ; //立即更新有效位
PWMCON2 |= 0X0001 ; //立即更新有效位
PWMCON3 |= 0X0001 ; //立即更新有效位
PTCON = 0x8000 ;//PWM模块使能
}
//***************************************
// 函数名称:Init_Pwm6
// 函数功能:初始化时钟
// 入口参数:时钟来源选择 处理器与CPU时钟分频比 pll倍频比
// 出口参数:无
// 返回值:无
//***************************************
void ToPwmValue(uint16 Tcon)
{
PDC1 = Tcon ; //pwm占空比寄存器
PDC2 = Tcon ;
PDC3 = Tcon ;
// MDC = Tcon; //主控占空比值
}
//应用实例
void main(void)
{
uint16 g_wTmp1 ;
//初始化PWM
//独立时期 独立占空比 PWM固定频率16K
Init_Pwm6(PWMCLK_DIV8,V_PTPER) ;//Fosc/8 16k pwm 最大占空比值为720
while(1)
{
ToPwmValue(200) ; //设置PWM占空比
PWMAH_ENB ; //输出PWM到H1管
PWMAH_DIS ;//禁止输出PWM到H1管
}
}
[3] dsPIC33EP timer1 初始化设立及应用
来源: 互联网 发布时间: 2014-02-18
dsPIC33EP timer1 初始化设置及应用
//文件 p33timer1.h
#ifndef _P33TIMER1_H_
#define _P33TIMER1_H_
//#include "p33timer1.h"
#define TIMER1_IEN_ENB _T1IE = 1
#define TIMER1_IEN_DIS _T1IE = 0
//timer1输入时钟分频
#define TIMER1_DIV1 (0<<4)
#define TIMER1_DIV8 (1<<4)
#define TIMER1_DIV64 (2<<4)
#define TIMER1_DIV256 (3<<4)
//=========================================
extern void Init_Timer1(uint16 T1div,uint16 Tcon) ;
#endif
//文件 p33timer1.c
#include "global.h"
#include "p33timer1.h"
//***************************************
// 函数名称:Init_Timer1
// 函数功能:初始化timer1
// 入口参数:时钟分频系数 定时器计数个数
// 出口参数:无
// 返回值:无
// Timer1 的时钟源 = Fp(即外设时钟)
//***************************************
void Init_Timer1(uint16 T1div,uint16 Tcon)
{
T1CON = 0X0000|T1div ;
PR1 = Tcon ; //重装载寄存器
TMR1 = 0x0000 ; //计数器
_T1IF = 0 ;
_T1IE = 0 ;
T1CON |= (1<<15) ; //开启定时器1
}
//应用实例
void main(void)
{
//外设时钟64分频到时钟 计数3599次
Init_Timer1(TIMER1_DIV64,3599) ;//
TIMER1_IEN_ENB ; //开启定时器中断
// TIMER1_IEN_DIS ;
while(1)
{
}
}
最新技术文章: